コード例 #1
0
 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);
 }
コード例 #2
0
        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);
        }