ConvertFrom-Markdown is used for converting a markdown document or string to a MarkdownInfo object. It can optionally return a HTML or VT100 encoded string in addition to a AST of the markdown document. Show-Markdown is used to either display the VT100 encoded string on console or redirect the HTML string to the browser. Set/Get-MarkdownOption cmdlets get be used to view or set markdown rendering options.
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Markdig;
|
|
using Markdig.Syntax;
|
|
using Markdig.Renderers;
|
|
|
|
namespace Microsoft.PowerShell.MarkdownRender
|
|
{
|
|
/// <summary>
|
|
/// Renderer for adding VT100 escape sequences for items in a list block.
|
|
/// </summary>
|
|
internal class ListItemBlockRenderer : VT100ObjectRenderer<ListItemBlock>
|
|
{
|
|
protected override void Write(VT100Renderer renderer, ListItemBlock obj)
|
|
{
|
|
var parent = obj.Parent as ListBlock;
|
|
|
|
if (parent != null)
|
|
{
|
|
if (!parent.IsOrdered)
|
|
{
|
|
foreach (var line in obj)
|
|
{
|
|
RenderWithIndent(renderer, line, parent.BulletType, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RenderWithIndent(VT100Renderer renderer, MarkdownObject block, char listBullet, int indentLevel)
|
|
{
|
|
// Indent left by 2 for each level on list.
|
|
string indent = "".PadLeft(indentLevel * 2);
|
|
|
|
var paragraphBlock = block as ParagraphBlock;
|
|
|
|
if(paragraphBlock != null)
|
|
{
|
|
renderer.Write(indent).Write(listBullet).Write(" ").Write(paragraphBlock.Inline);
|
|
}
|
|
else //If there is a sublist, the block is a ListBlock instead of ParagraphBlock.
|
|
{
|
|
var subList = block as ListBlock;
|
|
if (subList != null)
|
|
{
|
|
foreach(var subListItem in subList)
|
|
{
|
|
var subListItemBlock = subListItem as ListItemBlock;
|
|
|
|
if(subListItemBlock != null)
|
|
{
|
|
foreach (var line in subListItemBlock)
|
|
{
|
|
// Increment indent level for sub list.
|
|
RenderWithIndent(renderer, line, listBullet, indentLevel + 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|