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, HtmlBlock obj) { renderer.RenderLinesBefore(obj); //renderer.Write(obj.BeforeWhitespace); // Lines content is written, including whitespace renderer.WriteLeafRawLines(obj); renderer.RenderLinesAfter(obj); }
protected override void Write(RoundtripRenderer renderer, ThematicBreakBlock obj) { renderer.RenderLinesBefore(obj); renderer.Write(obj.Content); renderer.WriteLine(obj.NewLine); renderer.RenderLinesAfter(obj); }
protected override void Write(RoundtripRenderer renderer, ParagraphBlock paragraph) { renderer.RenderLinesBefore(paragraph); renderer.Write(paragraph.TriviaBefore); renderer.WriteLeafInline(paragraph); //renderer.Write(paragraph.Newline); // paragraph typically has LineBreakInlines as closing inline nodes renderer.RenderLinesAfter(paragraph); }
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, HeadingBlock obj) { if (obj.IsSetext) { renderer.RenderLinesBefore(obj); var headingChar = obj.Level == 1 ? '=' : '-'; var line = new string(headingChar, obj.HeaderCharCount); renderer.WriteLeafInline(obj); renderer.WriteLine(obj.SetextNewline); renderer.Write(obj.TriviaBefore); renderer.Write(line); renderer.WriteLine(obj.NewLine); renderer.Write(obj.TriviaAfter); renderer.RenderLinesAfter(obj); } else { renderer.RenderLinesBefore(obj); var headingText = obj.Level > 0 && obj.Level <= 6 ? HeadingTexts[obj.Level - 1] : new string('#', obj.Level); renderer.Write(obj.TriviaBefore); renderer.Write(headingText); renderer.Write(obj.TriviaAfterAtxHeaderChar); renderer.WriteLeafInline(obj); renderer.Write(obj.TriviaAfter); renderer.WriteLine(obj.NewLine); renderer.RenderLinesAfter(obj); } }
protected override void Write(RoundtripRenderer renderer, LinkReferenceDefinition linkDef) { renderer.RenderLinesBefore(linkDef); renderer.Write(linkDef.TriviaBefore); renderer.Write('['); renderer.Write(linkDef.LabelWithTrivia); renderer.Write("]:"); renderer.Write(linkDef.TriviaBeforeUrl); if (linkDef.UrlHasPointyBrackets) { renderer.Write('<'); } renderer.Write(linkDef.UnescapedUrl); if (linkDef.UrlHasPointyBrackets) { renderer.Write('>'); } renderer.Write(linkDef.TriviaBeforeTitle); if (linkDef.Title != null) { var open = linkDef.TitleEnclosingCharacter; var close = linkDef.TitleEnclosingCharacter; if (linkDef.TitleEnclosingCharacter == '(') { close = ')'; } renderer.Write(open); renderer.Write(linkDef.UnescapedTitle); renderer.Write(close); } renderer.Write(linkDef.TriviaAfter); renderer.Write(linkDef.NewLine.AsString()); renderer.RenderLinesAfter(linkDef); }
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); }