public string ToHtml(string markdown)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return("");
            }

            var pipeline = new MarkdownPipelineBuilder();
            MarkdownPipeline markdownPipeline = pipeline.UseAdvancedExtensions().Build();

            MarkdownObject doc    = Markdown.Parse(markdown, markdownPipeline);
            var            walker = new MarkdigImageAndLinkWalker(
                (e) =>
            {
                ImageParsed?.Invoke(e);
            },
                (e) =>
            {
                LinkParsed?.Invoke(e);
            });

            walker.WalkAndBindParseEvents(doc);

            var builder    = new StringBuilder();
            var textwriter = new StringWriter(builder);

            var renderer = new HtmlRenderer(textwriter);

            renderer.Render(doc);

            return(builder.ToString());
        }
Beispiel #2
0
 private void FixLinks(MarkdownDocument document)
 {
     foreach (var item in document.Descendants().OfType <LinkInline>())
     {
         LinkInline link = (LinkInline)item;
         if (item.IsImage)
         {
             ImageEventArgs args = new ImageEventArgs(link.Url, link.Url, link.Label, link.Label);
             ImageParsed?.Invoke(this, args);
             link.Url = args.Src;
         }
         else
         {
             LinkEventArgs args = new LinkEventArgs(link.Url, link.Url, link.Label, "");
             LinkParsed?.Invoke(this, args);
             link.Url = args.Href;
         }
     }
 }
Beispiel #3
0
 private void OnImageAdded(ImageParsedEventArgs e)
 {
     ImageParsed?.Invoke(this, e);
 }