forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFencedCodeBlockRenderer.cs
More file actions
44 lines (41 loc) · 1.57 KB
/
Copy pathFencedCodeBlockRenderer.cs
File metadata and controls
44 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.IO;
using Markdig;
using Markdig.Helpers;
using Markdig.Renderers;
using Markdig.Syntax;
namespace Microsoft.PowerShell.MarkdownRender
{
/// <summary>
/// Renderer for adding VT100 escape sequences for code blocks with language type.
/// </summary>
internal class FencedCodeBlockRenderer : VT100ObjectRenderer<FencedCodeBlock>
{
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();
}
}
}
}