protected override void Write(TsxRenderer renderer, LinkInline link) { if (renderer.EnableHtmlForInline) { renderer.Write(link.IsImage ? "<mdx.Img src=" : "<mdx.A href="); renderer.WriteEscapeUrl(link.Url, link.IsImage); renderer.WriteProps(link); } if (link.IsImage) { if (renderer.EnableHtmlForInline) { renderer.Write(" alt=\""); } var wasEnableHtmlForInline = renderer.EnableHtmlForInline; renderer.EnableHtmlForInline = false; renderer.WriteChildren(link); renderer.EnableHtmlForInline = wasEnableHtmlForInline; if (renderer.EnableHtmlForInline) { renderer.Write('"'); } } if (renderer.EnableHtmlForInline && !string.IsNullOrEmpty(link.Title)) { renderer.Write(" title=\""); renderer.WriteEscape(link.Title); renderer.Write('"'); } if (link.IsImage) { if (renderer.EnableHtmlForInline) { renderer.Write(" />"); } } else { if (renderer.EnableHtmlForInline) { renderer.Write('>'); } renderer.WriteChildren(link); if (renderer.EnableHtmlForInline) { renderer.Write("</mdx.A>"); } } }
protected override void Write(TsxRenderer renderer, EmphasisInline obj) { string?tag = null; if (renderer.EnableHtmlForInline) { var c = obj.DelimiterChar; tag = c switch { '~' => obj.DelimiterCount == 2 ? "Del" : "Sub", '^' => "Sup", '+' => "Ins", '=' => "Mark", '"' => "Cite", '*' or '_' => obj.DelimiterCount == 2 ? "Strong" : "Em", _ => throw new NotSupportedException($"Delimiter: {c}") }; renderer.Write("<mdx.").Write(tag).WriteProps(obj).Write('>'); } renderer.WriteChildren(obj); if (renderer.EnableHtmlForInline) { renderer.Write("</mdx.").Write(tag).Write('>'); } } }
protected override void Write(TsxRenderer renderer, ListBlock listBlock) { renderer.EnsureLine(); if (renderer.EnableHtmlForBlock) { if (listBlock.IsOrdered) { renderer.Write("<mdx.Ol"); if (listBlock.BulletType != '1') { renderer.Write(" type=\"").Write(listBlock.BulletType).Write('"'); } if (listBlock.OrderedStart is { } and not "1") { renderer.Write(" start={").Write(listBlock.OrderedStart).Write('}'); } renderer.WriteProps(listBlock); renderer.Write('>').WriteLine().Indent(); } else { renderer.Write("<mdx.Ul"); renderer.WriteProps(listBlock); renderer.Write('>').WriteLine().Indent(); } } foreach (var item in listBlock) { var listItem = (ListItemBlock)item; var previousImplicit = renderer.ImplicitParagraph; renderer.ImplicitParagraph = !listBlock.IsLoose; renderer.EnsureLine(); if (renderer.EnableHtmlForBlock) { renderer.Write("<mdx.Li").WriteProps(listItem).Write('>'); } renderer.WriteChildren(listItem); if (renderer.EnableHtmlForBlock) { renderer.Write("</mdx.Li>").WriteLine(); } renderer.EnsureLine(); renderer.ImplicitParagraph = previousImplicit; } if (renderer.EnableHtmlForBlock) { renderer.Dedent().Write(listBlock.IsOrdered ? "</mdx.Ol>" : "</mdx.Ul>").WriteLine(); } renderer.EnsureLine(); }
protected override void Write(TsxRenderer renderer, FooterBlock footer) { renderer.EnsureLine(); renderer.Write("<mdx.Footer").WriteProps(footer).Write(">"); var implicitParagraph = renderer.ImplicitParagraph; renderer.ImplicitParagraph = true; renderer.WriteChildren(footer); renderer.ImplicitParagraph = implicitParagraph; renderer.Write("</mdx.Footer>").WriteLine(); }
protected override void Write(TsxRenderer renderer, QuoteBlock obj) { renderer.EnsureLine(); if (renderer.EnableHtmlForBlock) { renderer.Write("<mdx.BlockQuote").WriteProps(obj).Write(">").WriteLine(); } var savedImplicitParagraph = renderer.ImplicitParagraph; renderer.ImplicitParagraph = false; renderer.WriteChildren(obj); renderer.ImplicitParagraph = savedImplicitParagraph; if (renderer.EnableHtmlForBlock) { renderer.Write("</mdx.BlockQuote>").WriteLine(); } renderer.EnsureLine(); }
protected override void Write(TsxRenderer renderer, DelimiterInline obj) { renderer.WriteEscape(obj.ToLiteral()); renderer.WriteChildren(obj); }