Create an HTML page
Converts a markdown document stream to a full HTML page with html, head and body elements.
npm i mkpage --save
For the command line interface install mkdoc globally (npm i -g mkdoc).
Create an HTML page:
mkcat README.md | mkpage --title=README | mkhtml > README.htmlUse a stylesheet:
mkcat README.md | mkpage --title=README --style=style.css | mkhtml > README.htmlCreate the stream and write a commonmark document:
var page = require('mkpage')
, ast = require('mkast');
ast.src('## Heading\n\nParagraph.')
.pipe(page())
.pipe(ast.stringify({indent: 2}))
.pipe(process.stdout);Usage: mkpage [-h] [--async] [--help] [--version] [--doctype=<val>]
[--charset=<val>] [--lang=<val>] [--title=<val>]
[--style=<path...>] [--script=<path...>] [--css=<file>]
[--javascript=<file>] [--favicon=<path>] [--media=<val>]
[--html-[ATTR]=<val...>] [--meta-[NAME]=<desc...>]
[--equiv-[NAME]=<desc...>] [--body-[ATTR]=<val...>]
[--element=<name>] [--attr-[NAME]=<val...>] [--app=<path...>]
[--header=<file>] [--footer=<file>]
Convert a document to an HTML page.
Options
-d, --doctype=[VAL] Doctype declaration (default: <!doctype html>)
-r, --charset=[VAL] Document charset (default: utf-8)
-l, --lang=[VAL] Language attribute (default: en-us)
-t, --title=[VAL] Document title
-s, --style=[PATH...] Paths for link elements
-S, --script=[PATH...] Paths for script elements
-c, --css=[FILE] Create style element from FILE
-j, --javascript=[FILE] Create script element from FILE
-f, --favicon=[PATH] Path to use for a favicon
-m, --media=[VAL] Set media attribute for stylesheets
--html-[ATTR]=[VAL...] Set attributes on the html element
--meta-[NAME]=[DESC...] Set meta data in document head
--equiv-[NAME]=[DESC...]
Set http-equiv meta data in document head
--body-[ATTR]=[VAL...] Set attributes on the body element
--element=[NAME] Container element for the input document
--attr-[NAME]=[VAL...] Set attributes on container element
--app=[PATH...] Script elements before the end of the body
--header=[FILE] Include file at start of document body
--footer=[FILE] Include file at end of document body
--async Add async attribute to script elements
-h, --help Display help and exit
--version Print the version and exit
[email protected]
page([opts][, cb])Create an HTML page.
See HtmlPage for more options.
Returns an output stream.
optsObject processing options.cbFunction callback function.
inputReadable input stream.outputWritable output stream.
HtmlPage([opts])Wraps a document stream with HTML code blocks for the doctype, html, head and body elements.
This implementation wraps the entire output in a DOCUMENT node which is terminated with an EOF after all output has been sent.
If the element option is given the input markdown document is wrapped in
a container element using the tag name given with the element option. In
this case you can use the attr map to set attributes on the container
element.
The meta option allows setting <meta name="" content="" /> elements in
the head of the document; for example keywords or author information.
Both the header and footer options are file paths; when specified the
files are loaded and parsed as markdown.
The data from the header file is written after the body element but before any container element. The data for the footer file is written after any container element and before the end of the body element.
If the title option is not given no title element is created.
The style and script options correspond to link and script elements
created in the head of the document, each entry should be the URL to use
for the href or src attribute.
When the favicon option is given it is a URL to an image to use as a
shortcut icon, the path should have a .png or .ico extension so that
the MIME type may be determined.
If the async option is given all script elements are given the async
attribute.
The app array lists URLs for script elements to create just before the
body element is closed; these script elements when given are guaranteed to
be the final elements before the body element is closed (after any footer
or container element).
You can set attributes on the html and body elements using the html and
body options.
optsObject stream options.
doctypeString document type declaration.langString=en-us language attribute for the html element.charsetString=utf-8 document character set.titleString document title.styleArray paths for link elements.scriptArray paths for script elements.cssString file path to inline css contents.javascriptString file path to inline javascript contents.faviconString path to use for a favicon link element.mediaString stylesheet media attribute.asyncBoolean=false add async attribute to script elements.htmlObject map of attributes for the html element.metaObject map of name and descriptions for meta elements.equivObject map of name and content for meta http-equiv elements.bodyObject map of attributes for the body element.elementString container element name.attrObject map of attributes for the container element.appArray paths for script elements before end of body.headerArray|String include files at start of body.footerArray|String include files at end of body.
MIT
Created by mkdoc on May 19, 2016