protected override void Write(RoundtripRenderer renderer, ListBlock listBlock) { renderer.RenderLinesBefore(listBlock); if (listBlock.IsOrdered) { for (var i = 0; i < listBlock.Count; i++) { var item = listBlock[i]; var listItem = (ListItemBlock)item; renderer.RenderLinesBefore(listItem); var bws = listItem.TriviaBefore.ToString(); var bullet = listItem.SourceBullet.ToString(); var delimiter = listBlock.OrderedDelimiter; renderer.PushIndent(new List <string> { $@"{bws}{bullet}{delimiter}" }); renderer.WriteChildren(listItem); renderer.RenderLinesAfter(listItem); } } else { for (var i = 0; i < listBlock.Count; i++) { var item = listBlock[i]; var listItem = (ListItemBlock)item; renderer.RenderLinesBefore(listItem); StringSlice bws = listItem.TriviaBefore; char bullet = listBlock.BulletType; StringSlice aws = listItem.TriviaAfter; renderer.PushIndent(new List <string> { $@"{bws}{bullet}{aws}" }); if (listItem.Count == 0) { renderer.Write(""); // trigger writing of indent } else { renderer.WriteChildren(listItem); } renderer.PopIndent(); renderer.RenderLinesAfter(listItem); } } renderer.RenderLinesAfter(listBlock); }
protected override void Write(RoundtripRenderer renderer, QuoteBlock quoteBlock) { renderer.RenderLinesBefore(quoteBlock); renderer.Write(quoteBlock.TriviaBefore); var indents = new string[quoteBlock.QuoteLines.Count]; for (int i = 0; i < quoteBlock.QuoteLines.Count; i++) { var quoteLine = quoteBlock.QuoteLines[i]; var wsb = quoteLine.TriviaBefore.ToString(); var quoteChar = quoteLine.QuoteChar ? ">" : ""; var spaceAfterQuoteChar = quoteLine.HasSpaceAfterQuoteChar ? " " : ""; var wsa = quoteLine.TriviaAfter.ToString(); indents[i] = (wsb + quoteChar + spaceAfterQuoteChar + wsa); } bool noChildren = false; if (quoteBlock.Count == 0) { noChildren = true; // since this QuoteBlock instance has no children, indents will not be rendered. We // work around this by adding empty LineBreakInlines to a ParagraphBlock. // Wanted: a more elegant/better solution (although this is not *that* bad). foreach (var quoteLine in quoteBlock.QuoteLines) { var emptyLeafBlock = new ParagraphBlock { NewLine = quoteLine.NewLine }; var newLine = new LineBreakInline { NewLine = quoteLine.NewLine }; var container = new ContainerInline(); container.AppendChild(newLine); emptyLeafBlock.Inline = container; quoteBlock.Add(emptyLeafBlock); } } renderer.PushIndent(indents); renderer.WriteChildren(quoteBlock); renderer.PopIndent(); if (!noChildren) { renderer.RenderLinesAfter(quoteBlock); } }
protected override void Write(RoundtripRenderer renderer, CodeBlock obj) { renderer.RenderLinesBefore(obj); if (obj is FencedCodeBlock fencedCodeBlock) { renderer.Write(obj.TriviaBefore); var opening = new string(fencedCodeBlock.FencedChar, fencedCodeBlock.OpeningFencedCharCount); renderer.Write(opening); if (!fencedCodeBlock.TriviaAfterFencedChar.IsEmpty) { renderer.Write(fencedCodeBlock.TriviaAfterFencedChar); } if (fencedCodeBlock.Info != null) { renderer.Write(fencedCodeBlock.UnescapedInfo); } if (!fencedCodeBlock.TriviaAfterInfo.IsEmpty) { renderer.Write(fencedCodeBlock.TriviaAfterInfo); } if (!string.IsNullOrEmpty(fencedCodeBlock.Arguments)) { renderer.Write(fencedCodeBlock.UnescapedArguments); } if (!fencedCodeBlock.TriviaAfterArguments.IsEmpty) { renderer.Write(fencedCodeBlock.TriviaAfterArguments); } /* TODO do we need this causes a empty space and would render html attributes to markdown. * var attributes = obj.TryGetAttributes(); * if (attributes != null) * { * renderer.Write(" "); * renderer.Write(attributes); * } */ renderer.WriteLine(fencedCodeBlock.InfoNewLine); renderer.WriteLeafRawLines(obj); renderer.Write(fencedCodeBlock.TriviaBeforeClosingFence); var closing = new string(fencedCodeBlock.FencedChar, fencedCodeBlock.ClosingFencedCharCount); renderer.Write(closing); if (!string.IsNullOrEmpty(closing)) { // See example 207: "> ```\nfoo\n```" renderer.WriteLine(obj.NewLine); } renderer.Write(obj.TriviaAfter); } else { var indents = new List <string>(); foreach (var cbl in obj.CodeBlockLines) { indents.Add(cbl.TriviaBefore.ToString()); } renderer.PushIndent(indents); WriteLeafRawLines(renderer, obj); renderer.PopIndent(); // ignore block newline, as last line references it } renderer.RenderLinesAfter(obj); }