markdownToHtml function
Converts a markdown
document into a HTML string.
markdown
The markdown document.
normalize
If true
normalizes indent.
Implementation
String markdownToHtml(String markdown,
{bool normalize = true,
Iterable<mk.BlockSyntax>? blockSyntaxes,
Iterable<mk.InlineSyntax>? inlineSyntaxes,
mk.ExtensionSet? extensionSet,
mk.Resolver? linkResolver,
mk.Resolver? imageLinkResolver,
bool inlineOnly = false}) {
if (markdown.isEmpty) return '';
if (normalize) markdown = normalizeIndent(markdown);
var markdownHtml = mk.markdownToHtml(markdown,
blockSyntaxes: blockSyntaxes ?? [],
inlineSyntaxes: inlineSyntaxes ?? [],
extensionSet: extensionSet,
linkResolver: linkResolver,
imageLinkResolver: imageLinkResolver,
inlineOnly: inlineOnly);
// allow attributes for url. For example:
// [GitHub](https://github.com/){:target="_blank"}
markdownHtml = regExpReplaceAll(
RegExp(r'(<a.*?)(>.*?</a>){:(.*?)}',
multiLine: false, caseSensitive: false),
markdownHtml,
r'$1 $3$2');
return markdownHtml;
}