markdownToHtml function

String markdownToHtml(
  1. String markdown, {
  2. Iterable<BlockSyntax> blockSyntaxes = const [],
  3. Iterable<InlineSyntax> inlineSyntaxes = const [],
  4. ExtensionSet? extensionSet,
  5. Resolver? linkResolver,
  6. Resolver? imageLinkResolver,
  7. bool inlineOnly = false,
  8. bool encodeHtml = true,
  9. bool enableTagfilter = false,
  10. bool withDefaultBlockSyntaxes = true,
  11. bool withDefaultInlineSyntaxes = true,
  12. dynamic options,
  13. bool checkable = false,
  14. bool preserveSpace = false,
})

Converts the given string of Markdown to HTML.

Implementation

String markdownToHtml(
  String markdown, {
  Iterable<BlockSyntax> blockSyntaxes = const [],
  Iterable<InlineSyntax> inlineSyntaxes = const [],
  ExtensionSet? extensionSet,
  Resolver? linkResolver,
  Resolver? imageLinkResolver,
  bool inlineOnly = false,
  bool encodeHtml = true,
  bool enableTagfilter = false,
  bool withDefaultBlockSyntaxes = true,
  bool withDefaultInlineSyntaxes = true,
  dynamic options,
  bool checkable = false,
  bool preserveSpace = false,
}) {
  final document = Document(
    blockSyntaxes: blockSyntaxes,
    inlineSyntaxes: inlineSyntaxes,
    extensionSet: extensionSet,
    linkResolver: linkResolver,
    imageLinkResolver: imageLinkResolver,
    encodeHtml: encodeHtml,
    withDefaultBlockSyntaxes: withDefaultBlockSyntaxes,
    withDefaultInlineSyntaxes: withDefaultInlineSyntaxes,
    options: options,
    checkable: checkable,
    preserveSpace: preserveSpace,
  );

  if (inlineOnly) {
    return renderToHtml(document.parseInline(markdown),
        preserveSpace: preserveSpace);
  }

  final nodes = document.parse(markdown);

  return '${renderToHtml(nodes, enableTagfilter: enableTagfilter,
      preserveSpace: preserveSpace)}\n';
}