(html-)segment
Wrap headings and their contents in semantic section containers.
Usage
Segment can either be used in the browser (segment.browser.js
), as a module or preprocessing tool (segment.module.js
).
Browser
Simply add segment.browser.js
as a script in the page you want to segment.
...page contents...
The browser version attaches the segment class to the window object as htmlSegment
, allowing you to initialize it with new htmlSegment(document[, config])
. Pass it the document object and an optional configuration object.
// e.g. main.jslet segment = document
By default, this will automatically wrap all headings and their contents in <section>
containers.
Module
$ yarn add html-segment --dev
Include it in your module:
// ES6 // ES5var segment =
This will import the dist/segment.module.js
version.
Options
Preprocessing
Segment can also be used to alter static documents in a backend environment like node.js. Initialization works differently in this scenario since there isn't a window or document object to use.
jsdom Example
This example creates a document object using jsdom, processes it with html-segment, and then saves the result as a new html file.
// ES6 & Node.js // equivalent to `const htmlSegment = require('html-segment')` const dirs = input: './documents/input' output: './documents/output' const filename = 'myFile.html' // read the filefs