Pup

v2.x

ModulesparseMarkdown.js

The /modules/parseMarkdown.js module is used for parsing Markdown strings into HTML. In Pup, this is used in the <ViewDocument /> component for displaying any Markdown in the document body as HTML.

To aid in the process of parsing Markdown strings, Pup relies on the commonmark package and accompanying ruleset.

/modules/parseMarkdown.js
import { Parser, HtmlRenderer } from 'commonmark';

export default (markdown, options) => {
  const reader = new Parser();
  const writer = options ? new HtmlRenderer(options) : new HtmlRenderer();
  const parsed = reader.parse(markdown);
  return writer.render(parsed);
};