Markdown.compileToHtmlFileFromMdFile()

Load a markdown file from disk, compile to HTML, then save it back to disk.

Expects GitHub-flavored Markdown syntax. Uses [`marked`](https://github.com/chjj/marked). Specifically, here's how this method works: Steps: ====== + stream bytes from disk + when all bytes are in RAM, convert the source markdown to HTML + send the bytes of the (possibly now-transformed) HTML to the path on disk specified by `dest.html` as a write stream. When the stream finishes, call the async callback to signal that this markdown file has been compiled to HTML and written to disk successfully.

Usage

Hover over inputs/exits for more info.

var Markdown = require('machinepack-markdown');


// Load a markdown file from disk, compile to HTML, then save it back to disk.

Markdown.compileToHtmlFileFromMdFile({

src: '.tmp/compile-markdown-tree/some/markdown/file.md',

dest: '.tmp/public/templates/documentation/reference',

escapeHtml: false,

compileCodeBlock: '->',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Could not read source file from disk.

couldNotRead: function () {

 

},

// Could not write file back to disk.

couldNotWrite: function () {

 

},

// Could not compile markdown to HTML.

couldNotCompile: function () {

 

},

// Could not parse "docmeta" tags.

couldNotParse: function () {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

src required

Path (relative or absolute) to the Markdown file to convert.

'.tmp/compile-markdown-tree/some/markdown/file.md'
dest required

Path (relative or absolute) to the HTML file to create.

'.tmp/public/templates/documentation/reference'
escapeHtml

If enabled, any inline HTML in the source Markdown will be escaped instead of injected literally in the HTML output.

false
compileCodeBlock

An optional lifecycle callback useful for adding syntax highlighting to code blocks, or to perform custom HTML-escaping on them.

'->'

Exits

error

An unexpected error occurred.

couldNotRead

Could not read source file from disk.

couldNotWrite

Could not write file back to disk.

couldNotCompile

Could not compile markdown to HTML.

couldNotParse

Could not parse "docmeta" tags.

success

OK.

{}