Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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, LinkReferenceDefinitionGroup obj)
 {
     renderer.WriteChildren(obj);
 }