Exemplo n.º 1
0
 protected override void Write(VT100Renderer renderer, LinkInline obj)
 {
     // Format link as image or link.
     if (obj.IsImage)
     {
         renderer.Write(renderer.EscapeSequences.FormatImage(obj.FirstChild.ToString()));
     }
     else
     {
         renderer.Write(renderer.EscapeSequences.FormatLink(obj.FirstChild.ToString(), obj.Url));
     }
 }
        private void RenderWithIndent(VT100Renderer renderer, MarkdownObject block, char listBullet, int indentLevel)
        {
            // Indent left by 2 for each level on list.
            string indent = Padding(indentLevel * 2);

            if (block is ParagraphBlock paragraphBlock)
            {
                renderer.Write(indent).Write(listBullet).Write(" ").Write(paragraphBlock.Inline);
            }
            else
            {
                // If there is a sublist, the block is a ListBlock instead of ParagraphBlock.
                if (block is ListBlock subList)
                {
                    foreach (var subListItem in subList)
                    {
                        if (subListItem is ListItemBlock subListItemBlock)
                        {
                            foreach (var line in subListItemBlock)
                            {
                                // Increment indent level for sub list.
                                RenderWithIndent(renderer, line, listBullet, indentLevel + 1);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void Write(VT100Renderer renderer, FencedCodeBlock obj)
        {
            if (obj?.Lines.Lines != null)
            {
                foreach (StringLine codeLine in obj.Lines.Lines)
                {
                    if (!string.IsNullOrWhiteSpace(codeLine.ToString()))
                    {
                        // If the code block is of type YAML, then tab to right to improve readability.
                        // This specifically helps for parameters help content.
                        if (string.Equals(obj.Info, "yaml", StringComparison.OrdinalIgnoreCase))
                        {
                            renderer.Write("\t").WriteLine(codeLine.ToString());
                        }
                        else
                        {
                            renderer.WriteLine(renderer.EscapeSequences.FormatCode(codeLine.ToString(), isInline: false));
                        }
                    }
                }

                // Add a blank line after the code block for better readability.
                renderer.WriteLine();
            }
        }
 private static void RenderNumberedList(VT100Renderer renderer, ListItemBlock block, int index)
 {
     // For a numbered list, we need to make sure the index is incremented.
     foreach (var line in block)
     {
         if (line is ParagraphBlock paragraphBlock)
         {
             renderer.Write(index.ToString()).Write(". ").Write(paragraphBlock.Inline);
         }
     }
 }
Exemplo n.º 5
0
        protected override void Write(VT100Renderer renderer, QuoteBlock obj)
        {
            // Iterate through each item and add the quote character before the content.
            foreach (var item in obj)
            {
                renderer.Write(obj.QuoteChar).Write(" ").Write(item);
            }

            // Add blank line after the quote block.
            renderer.WriteLine();
        }
Exemplo n.º 6
0
 protected override void Write(VT100Renderer renderer, LineBreakInline obj)
 {
     // If it is a hard line break add new line at the end.
     // Else, add a space for after the last character to improve readability.
     if (obj.IsHard)
     {
         renderer.WriteLine();
     }
     else
     {
         renderer.Write(" ");
     }
 }
Exemplo n.º 7
0
 protected override void Write(VT100Renderer renderer, LeafInline obj)
 {
     // If the next sibling is null, then this is the last line in the paragraph.
     // Add new line character at the end.
     // Else just write without newline at the end.
     if (obj.NextSibling == null)
     {
         renderer.WriteLine(obj.ToString());
     }
     else
     {
         renderer.Write(obj.ToString());
     }
 }
        protected override void Write(VT100Renderer renderer, ListBlock obj)
        {
            // start index of a numbered block.
            int index = 1;

            foreach (var item in obj)
            {
                if (item is ListItemBlock listItem)
                {
                    if (obj.IsOrdered)
                    {
                        RenderNumberedList(renderer, listItem, index++);
                    }
                    else
                    {
                        renderer.Write(listItem);
                    }
                }
            }

            renderer.WriteLine();
        }
Exemplo n.º 9
0
 protected override void Write(VT100Renderer renderer, EmphasisInline obj)
 {
     renderer.Write(renderer.EscapeSequences.FormatEmphasis(obj.FirstChild.ToString(), isBold: obj.DelimiterCount == 2 ? true : false));
 }
Exemplo n.º 10
0
 protected override void Write(VT100Renderer renderer, CodeInline obj)
 {
     renderer.Write(renderer.EscapeSequences.FormatCode(obj.Content, isInline: true));
 }