Skip to content

Instantly share code, notes, and snippets.

@deanebarker
Last active February 14, 2025 13:48
Show Gist options
  • Select an option

  • Save deanebarker/64aace9d2fe21d88f86df98a20bd22ba to your computer and use it in GitHub Desktop.

Select an option

Save deanebarker/64aace9d2fe21d88f86df98a20bd22ba to your computer and use it in GitHub Desktop.
How to iterate and manipulate a parsed Markdig document
var markdown = @"
This is some text.
This is a [link](http://deanebarker.net/)
";
var builder = new MarkdownPipelineBuilder();
var pipeline = builder.Build();
var document = Markdown.Parse(markdown, pipeline);
// Iterate the links in the doc; you can change the parsed doc here...
foreach (LinkInline link in document.Descendants<LinkInline>())
{
// If they're not using SSL, fix it...
if(link.Url.Contains("deanebarker.net") && link.Url.StartsWith("http://"))
{
link.Url = link.Url.Replace("http://", "https://");
}
}
var result = document.ToHtml(pipeline);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment