/// <summary> /// Parses the given markdown into an AST. /// </summary> /// <param name="markdown"></param> /// <returns></returns> protected string RenderMarkdown(string markdown) { var parser = new Markdown(); parser.Parse(markdown); var richTextBlock = new RichTextBlock(); var renderer = new RenderToRichTextBlock(richTextBlock, new DummyLinkRegister()); renderer.Render(parser); var result = new StringBuilder(); foreach (var block in richTextBlock.Blocks) { SerializeElement(result, block, indentLevel: 0); } return result.ToString(); }
/// <summary> /// Fired when the markdown is changed. /// </summary> /// <param name="newMarkdown"></param> private void OnMarkdownChanged(string newMarkdown) { OnMarkdownReadyArgs args = new OnMarkdownReadyArgs(); // Clear the current content CleanUpTextBlock(); // Make sure we have something to parse. if (!String.IsNullOrWhiteSpace(newMarkdown)) { try { // Try to parse the markdown. Markdown markdown = new Markdown(); markdown.Parse(newMarkdown); // Now try to display it RenderToRichTextBlock rendner = new RenderToRichTextBlock(ui_richTextBox, this); rendner.Render(markdown); } catch (Exception e) { DebuggingReporter.ReportCriticalError("Error while parsing and rendering: " + e.Message); args.WasError = true; args.Exception = e; } } // #todo indicate if ready m_onMarkdownReady.Raise(this, args); }