protected override void Write(RoundtripRenderer renderer, ThematicBreakBlock obj) { renderer.RenderLinesBefore(obj); renderer.Write(obj.Content); renderer.WriteLine(obj.NewLine); renderer.RenderLinesAfter(obj); }
public void WriteLeafRawLines(RoundtripRenderer renderer, LeafBlock leafBlock) { if (leafBlock.Lines.Lines != null) { var lines = leafBlock.Lines; var slices = lines.Lines; for (int i = 0; i < lines.Count; i++) { ref StringSlice slice = ref slices[i].Slice; renderer.Write(ref slice); renderer.WriteLine(slice.NewLine); } }
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, 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); }