unified-doc-parse-code-block
unified-doc parser to parse content into a hast tree with a single code block node i.e. <pre><code>{content}</code></pre>
.
Install
npm install unified-doc-parse-code-block
Use
;; const content = `var hello = "hi"; var world = "earth";` const processor = ; ;
API
unified().use(content[, options])
hast
parser to parse content into a single code block node i.e. <pre><code>{content}</code></pre>
.
Use the parser with any unified processor. Note that this plugin can be conveniently used with various rehype syntax highlighting plugins (e.g rehype-higlight
or rehype-prism
) to further tokenize code block content for highlighting using stylesheets in the corresponding ecosystems.
Example
;;; const content = `var hello = "hi"; var world = "earth";` ; // apply relevant highlight.js to the rendered content
options
When the language
option is provided, attach the equivalent language
to the CSS class name of the pre
and code
nodes. Note that this is recommended by the HTML 5 spec to semantically inform the language of the computer code that is being marked up. It is also used as an identifier for syntax highlighting libraries (e.g. highlight.js
or prism.js
) to highlight code content.