npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

asciidoctor-chunker

v1.0.6

Published

Creates chunked (multi-page) HTML from Asciidoctor's single HTML file with supporting the fine-tuned splits in chapters, sections and any depth of subsections.

Downloads

611

Readme

asciidoctor-chunker

npm version Node.js CI License: MIT

Generates chunked (multi-page) HTML from Asciidoctor's single HTML file with the support of fine-tuned splits by chapters, sections, or any depth of subsections. Here is the sample output. Each chapter can have different levels of extraction depth. See What it does for details. The asciidoctor-chunker is written in JavaScript and is very easy to install. See Installation.

Latest News

See CHANGELOG.md for the complete history

  • 2023/2/20 Ver 1.0.6 Page navigation is disabled with shift+arrow (thanks to @chloekek).
  • 2022/9/14 Ver 1.0.5 Node.js v18.x is supported. The npm installs the shebang script so you can invoke asciidoctor-chunker with npx. When the target link within the document is missing, the anchor is still created with target-missing class attribute.
  • 2021/8/3 Ver 1.0.4 Added the keyboard shotcuts for the page navigation with arrow keys. Added the accessibility labels on the page navigation for screen readers.
  • 2021/6/25 Ver 1.0.3 Fixed the security vulnerabilities in the dependencies.
  • 2021/5/9 Ver 1.0.2 The toc item for the titlepage can be configured with --titlePage option (thanks to @johnthad).

What it does

Asciidoctor-Chunker generates chunked HTML from a single HTML generated by Asciidoctor.

  1. Splits part preambles and chapters (or any depth of section level) into separate files. Each chapter can be configured to have a different depth for extractions.
  2. Extracts css inside the style element into a separate file so the browser can cache and share it among all the pages.
  3. Places footnotes in the file they belong to. This also means that the multiply referred footnotes are placed in every referrer's files and sets the link back to the referrer's id within the page.
  4. Re-writes the relative links (cross references) in order to point to the appropriate chunked files. The target-missing class attribute is added to the anchor when the link target is missing (is undefined in the source document).
  5. Copies the local images and linked files (with link, script and img tags) whose paths are relative, to the directory relative to the chunked html output. Files are only copied if they are new or modified compared to the previously copied one.
  6. Adds a titlepage link in the toc and non-opinionated page navigation at the bottom of each page. Arrow-keys navigation is supported.
  7. Highlights the current page toc items and they get scrolled into the viewport.

Here is the sample output created from the Asciidoctor User Manual. The footer on the sample page is added by setting the asciidoctor attribute and is not added by asciidoctor-chunker.

Installation

Asciidoctor-Chunker is written in JavaScript and runs with NodeJS.

  1. Install Node.js, the JavaScript runtime. This will install npm, the package manager CLI for Node.js.
  2. If you want to install globally, invoke the following;
    npm install -g asciidoctor-chunker
    You can install locally under the current directory as;
    npm install asciidoctor-chunker
  3. Or alternatively you can download the pre-built program from the release.

Usage

If you installed globally:

asiidoctor-chunker [single-html-file] -o [output-directory]

If you installed locally invoke the following under the directory you installed:

npx asciidoctor-chunker [single-html-file] -o [output-directory]

If you installed the prebuild program simply run the script as:

./asciidoctor-chunker.js [single-html-file] -o [output-directory]

[single-html-file] is the single HTML file generated by Asciidoctor from the book doctype. If the output directory is not specified, the default is html_chunks under the current directory.

More discription of usage is available with --help option.

How to Configure the Depth of Extraction

You can list the multiple settings by connecting each specifier with a comma. Each specifier is consisted of either a single number or a collon separated with two numbers.

The single number sets the default level of extraction. Number 1 is the application's default and it extracts the chapter level. Number 2 for section extraction, 3 for subsection, and so on to 6 which is the maximum section level of Asciidoctor.

The list of collon separated numbers, chap:level, can change the extraction depth for specific chapters, so 3:2 means chapter 3 is extracted down to 2 levels (ie. section level). You can use a hyphen to specify the range of chapters to set as chapFrom-chapTo:level, so 1-3:5 means chapter 1 through 5 should be extracted with the depth level 5.

Example:

  --depth 2          The default level 2, all the chapters and
                     sections will be extracted.
  --depth 3,1:2,8:5  The default level 3, level 2 for Chap 1,
                     level 5 for Chap 8.
  --depth 1,3-8:2    The default level 1, level 2 for Chap 3 to 8.
  --depth 3-8:3      No default is set so default level is 1, and
                     level 3 for chap3 to 8.`

Custom CSS

By default asciidoctor-chunker.css is included in the output directory. It provides the non-opinionated page navigation at the bottom of every chunked page. You can override this by giving a comma separated list of paths to your custom css files. They are copied into the output directory so the paths must be accessible by asciidoctor-chunker.

About Strict Mode

If you have any custom elements inserted under <div id=#content></div> in the source single html, asciidoctor-chunker ignores it by default. If you want them to be included into the chunked html, set the option --no-strictMode. The element will be copied to every chunked page.

Customizing Titlepage

The index.html created by asciidoctor-chunker is selected by clicking the word Titlepage in the table of contents. To change the default value, use the option --titlePage [string] where [string] is the desired text.

Example

The project contains the example directory where you can generate the chunked html for the Asciidoctor User Manual by invoking make. Simply go into the example directory and invoke make. This will clone the asciidoctor project from the github for the first time, then the chunked html will be generated under test/output-chunk/html_chunk/ directory. The index.html is the first page.

$ cd example
$ make

Related Projects

License

MIT

Developer's Memo

  • Unit test uses test/resources/output/single/sample.html generated from test/resources/sample.adoc.
  • npm install cheerio commander
  • npm install --save-dev ava webpack webpack-cli webpack-shebang-plugin
  • Filename related modules: Toc.mjs