forked from Knagis/CommonMark.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Dmitry Shechtman edited this page Dec 27, 2015
·
4 revisions
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());
}