internal/functions/ConvertFrom-MdBlock.ps1

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function ConvertFrom-MdBlock
{
<#
    .SYNOPSIS
        Converts special blocks defined in markdown into html.
     
    .DESCRIPTION
        Converts special blocks defined in markdown into html.
        The resultant html is appended to the stringbuilder specified.
        The conversion logic is provided by Register-EBMarkdownBlock.
        Returns whether the next line should be a first paragraph or a regular paragraph.
     
    .PARAMETER Type
        What kind of block is this?
     
    .PARAMETER Lines
        The lines of text contained in the block.
     
    .PARAMETER Attributes
        Any attributes provided to the block.
     
    .PARAMETER StringBuilder
        The stringbuilder containing the overall html string being built.
     
    .EXAMPLE
        PS C:\> ConvertFrom-MdBlock -Type $type -Lines $lines -Attributes @{ } -StringBuilder $builder
     
        Converts the provided block data to html and appends it to the stringbuilder.
        Returns whether the next line should be a first paragraph or a regular paragraph.
#>

    [CmdletBinding()]
    param (
        [parameter(Mandatory = $true)]
        [string]
        $Type,
        
        [parameter(Mandatory = $true)]
        [AllowEmptyCollection()]
        [AllowEmptyString()]
        [string[]]
        $Lines,
        
        [parameter(Mandatory = $true)]
        [System.Collections.Hashtable]
        $Attributes,
        
        [parameter(Mandatory = $true)]
        [System.Text.StringBuilder]
        $StringBuilder
    )
    
    process
    {
        $converter = $script:mdBlockTypes[$Type]
        if (-not $converter)
        {
            Stop-PSFFunction -Message "Converter for block $Type not found! Make sure it is properly registered using Register-EBMarkdownBlock" -EnableException $true -Cmdlet $PSCmdlet -Category InvalidArgument
        }
        
        $data = [pscustomobject]($PSBoundParameters | ConvertTo-PSFHashtable)
        $converter.Invoke($data) -as [bool]
    }
}