lask79 / asciidoctor-treeview

Generates tree views based on ascii-tree with beautiful icons for folders and icons
Mozilla Public License 2.0
10 stars 0 forks source link
antora asciidoctor-extension asciidoctorjs extension treeview

= asciidoctor-treeview :url-repo: https://github.com/lask79/asciidoctor-treeview :url-antora-docs: https://docs.antora.org/antora/3.1 :toc: macro :toc-title: Contents :sectnums: :imagesdir: docs/modules/ROOT/images

image::https://img.shields.io/npm/v/asciidoctor-treeview.svg[NPM version]

toc::[]

asciidoctor-treeview is an extension for asciidoctor.js and Antora that generates a treeview based on several input formats and displays beautiful icons for folders and files.

== Features

[%header,cols="2a,2a""] |=== |Source |Result

| [source, plaintext]

[treeview]

.

|===

== Installation

npm i asciidoctor-treeview

== Register extension

=== Asciidoctor

.Asciidoctor [source, javascript]

const asciidoctor = require('@asciidoctor/core')() const asciidoctorTreeView = require('asciidoctor-treeview') const registry = asciidoctor.Extensions.create() asciidoctorTreeView.register(registry)

NOTE: The needed css file is added via DocInfoProcessor.

=== Antora

==== Antora Playbook [source, yaml]

antora: extensions:

WARNING: Do not add the asciidoctor-treeview to the asciidoc.extensions. It will not work because then the needed css will not be added to the site.

==== Add handlebars template

You have to change 1 file in your Antora UI bundle or by overwriting it via supplemental-ui:

If you do not want to change your UI bundle or when you use the default ui bundle you can simply put the following lines into supplemental-ui/partials/head-styles.hbs next to your antora playbook:

.head-styles.hbs [source,html]

{{> treeview-styles }}

{{> treeview-styles }} will be replaced with the content of the file treeview-styles.hbs that provided by this extension.

.treeview-styles.hbs [source,html]


The treeview.css file contains some treeview specific styles that are needed to render the code blocks correctly and overrides some styles defined in the https://docs.antora.org/antora-ui-default/[Antora UI Default].

=== VSCode

.VSCode [source,javascript]

// add this to .asciidoctor/lib/asciidoctor-treeview.js when you have turned on the extension module.exports = require('asciidoctor-treeview')

== Usage

[%header,cols="^1s,4a,2a""] |=== |Type |Source |Result

ascii-tree

[source, plaintext]

[treeview]

. ├── .vscode │ ├── extensions.json │ └── settings.json ├── data │ ├── config │ │ ├── default.json │ │ ├── full.json │ │ └── minimal.json │ └── templates │ ├── treeview.css.hbs │ └── treeview.js.hbs ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .npmignore ├── .stylelintrc ├── LICENSE └── package.json


|image:small-structure-result.png[width=300]

Hash Symbol

[source, plaintext]

[treeview]

.

.vscode

extensions.json

settings.json

data

config

default.json

full.json

minimal.json

templates

treeview.css.hbs

treeview.js.hbs

.editorconfig

.eslintrc

.gitignore

.npmignore

.stylelintrc

LICENSE

package.json



|image:small-structure-result.png[width=300]

* Symbol

[source, plaintext]

[treeview]

.

Custom Symbol

[source, plaintext]

[treeview,symbol="-"]

.

== Configuration

=== Asciidoc Attributes

==== treeview-theme Default: dark

[source,plaintext]

:treeview-theme: light

[source,plaintext]

[treeview,theme=light]

---- [treeview,theme=dark] ---- ---- -------- ==== treeview-icon-source `Default: jsdelivr` * Use `treeview-icon-source` attribute on document * Supported values: ** `jsdelivr` (default) => downloads from CDN ** `embedded` => embeds the icons into the css as data-uri ** `antora` => copies icons into UI catalog ** `` => configure your own or url to the folder that contains the icons. *Examples:* .Embed icons as data-uri in CSS [source,plaintext] ---- = Document Title :treeview-icon-source: embedded ---- .Use custom url [source,plaintext] ---- = Document Title :treeview-icon-source: https://example.com/cdn/icons ---- The icon name like file.svg will be added as suffix to the given url. === Antora [source, yaml] ---- antora: extensions: - require: "asciidoctor-treeview" icon_source: antora # or embedded or jsdelivr ---- `Default: antora` * Use `icon-source` attribute on document * Supported values: ** `antora` (default) => copies icons into UI catalog ** `jsdelivr` => downloads from CDN ** `embedded` => embeds the icons into the css as data-uri WARNING: The asciidoctor attribute `treeview-icon-source` will be ignored when antora is used. == Symbol Based Parser * Symbols * and # are already autodetected. * If you want to use a custom symbol like '-' then you need to configure it on the treeview block. .Autodetected symbol # [source,plaintext] -------- [treeview,symbol="-"] ---- . - .vscode -- extensions.json -- settings.json ---- -------- == HowTos I want to mark a line as folder even when it does not have children:: Put a `/` at the end of the name. Then that line will be marked as a folder. + [source,asciidoc] -------- [treeview] ---- . # folder/ # second-folder/ ---- -------- I want to add comments to a line:: Put `//` at the end of the line. Then that line will be marked as a comment. + [source,asciidoc] -------- [treeview] ---- . # README.md // this is a comment ---- -------- == Changelog === v1.0.0-alpha.7 * *Features* ** add support for different icon sources https://github.com/lask79/asciidoctor-treeview/pull/8[(#8)] *** `jsdelivr` (default) => downloads from CDN *** `embedded` => embeds the icons into the css as data uri *** `antora` => copies icons into UI catalog *** `` => configure your own path or url * *Refactoring* ** Now generates a treeview.css that uses urls for the different icons instead of creating image tags inside of the document. ** Uses roles on an tag to define the icons. ** There are now new dependencies to `handlebars` and `material-icons-theme`. ** Collects all used icons and uses them to generate the css and copies only the used icons to the UI catalog === v1.0.0-alpha.6 * *Features* ** allow comments on lines https://github.com/lask79/asciidoctor-treeview/pull/6[(#6)] ** mark lines as folders (see HowTos) * *Fixes* ** do not render empty lines as files without name allow comments on lines https://github.com/lask79/asciidoctor-treeview/pull/5[(#5)]