Home - AMDL/CommonMark.NET GitHub Wiki
Extensibility
Block.AsEnumerable()
Provides an easy solution to visit every node of the parsed markdown document and perform simple modifications.
// parse markdown into document structure
var document = CommonMarkConverter.Parse("[click this link](~/hello)");
// walk the document node tree
foreach (var node in document.AsEnumerable())
{
if (
// start and end of each node may be visited separately
node.IsOpening
// blocks are elemets like paragraphs and lists, inlines are
// elements like emphasis, links, images.
&& node.Inline != null
&& node.Inline.Tag == InlineTag.Link)
{
if (node.Inline.TargetUrl.StartsWith("~"))
node.Inline.TargetUrl = "http://server/app/" +
node.Inline.TargetUrl.Substring(1);
}
}
using (var writer = new System.IO.StringWriter())
{
// write the HTML output
CommonMarkConverter.ProcessStage3(document, writer);
Console.WriteLine(writer.ToString());
}