/// <summary> /// Initializes a new instance of the <see cref="VT100EscapeSequences"/> class. /// </summary> /// <param name="optionInfo">MarkdownOptionInfo object to initialize with.</param> public VT100EscapeSequences(MarkdownOptionInfo optionInfo) { if (optionInfo == null) { throw new ArgumentNullException("optionInfo"); } options = optionInfo; }
/// <summary> /// Initializes a new instance of the <see cref="VT100Renderer"/> class. /// </summary> /// <param name="writer">TextWriter to write to.</param> /// <param name="optionInfo">MarkdownOptionInfo object with options.</param> public VT100Renderer(TextWriter writer, MarkdownOptionInfo optionInfo) : base(writer) { EscapeSequences = new VT100EscapeSequences(optionInfo); // Add the various element renderers. ObjectRenderers.Add(new HeaderBlockRenderer()); ObjectRenderers.Add(new LineBreakRenderer()); ObjectRenderers.Add(new CodeInlineRenderer()); ObjectRenderers.Add(new FencedCodeBlockRenderer()); ObjectRenderers.Add(new EmphasisInlineRenderer()); ObjectRenderers.Add(new ParagraphBlockRenderer()); ObjectRenderers.Add(new LeafInlineRenderer()); ObjectRenderers.Add(new LinkInlineRenderer()); ObjectRenderers.Add(new ListBlockRenderer()); ObjectRenderers.Add(new ListItemBlockRenderer()); ObjectRenderers.Add(new QuoteBlockRenderer()); }
/// <summary> /// Convert from Markdown string to VT100 encoded string or HTML. Returns MarkdownInfo object. /// </summary> /// <param name="markdownString">String with Markdown content to be converted.</param> /// <param name="conversionType">Specifies type of conversion, either VT100 or HTML.</param> /// <param name="optionInfo">Specifies the rendering options for VT100 rendering.</param> /// <returns>MarkdownInfo object with the converted output.</returns> public static MarkdownInfo Convert(string markdownString, MarkdownConversionType conversionType, MarkdownOptionInfo optionInfo) { var renderInfo = new MarkdownInfo(); var writer = new StringWriter(); MarkdownPipeline pipeline = null; if (conversionType.HasFlag(MarkdownConversionType.HTML)) { pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); var renderer = new Markdig.Renderers.HtmlRenderer(writer); renderInfo.Html = Markdig.Markdown.Convert(markdownString, renderer, pipeline).ToString(); } if (conversionType.HasFlag(MarkdownConversionType.VT100)) { pipeline = new MarkdownPipelineBuilder().Build(); // Use the VT100 renderer. var renderer = new VT100Renderer(writer, optionInfo); renderInfo.VT100EncodedString = Markdig.Markdown.Convert(markdownString, renderer, pipeline).ToString(); } // Always have AST available. var parsed = Markdig.Markdown.Parse(markdownString, pipeline); renderInfo.Tokens = parsed; return(renderInfo); }