Convert-MarkdownToHTMLFragment

Convert Markdown text to HTML fragments.

Syntax

 Convert-MarkdownToHTMLFragment [-InputObject] <Object> [-IncludeExtension] <String[]> [-ExcludeExtension] <String[]>  [<CommonParameters>] 

Description

Converts Markdown text to HTML fragments using configured Markdown extensions.

Parameters

-InputObject <Object>

The input object can have one of the following of types:

  • An annotated [System.IO.FileInfo] object as emitted by Find-MarkdownFiles.

  • A plain markdown string [string].

  • A markdown descriptor object which is basically a [hashtable] whith following contents:

    Key Value Type Description
    Markdown [string] The markdown text.
    RelativePath [string] Relative path of the html file below the site directory.

Parameter Property Value
Required? true
Position? 1
Default value ``
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-IncludeExtension <String[]>

Comma separated list of Markdown parsing extension names. See Markdown extensions for an annotated list of supported extensions.


Parameter Property Value
Required? false
Position? 2
Default value @('advanced')
Accept pipeline input? false
Accept wildcard characters? false

-ExcludeExtension <String[]>

Comma separated list of Markdown parsing extensions to exclude. Mostly used when the the 'advanced' parsing option is included and certain individual options need to be removed.


Parameter Property Value
Required? false
Position? 3
Default value @()
Accept pipeline input? false
Accept wildcard characters? false

Inputs

Markdown text [string], Markdown file [System.IO.FileInfo], or a markdown descriptor [hashtable].

Outputs

HTML fragment object with following properties:

Property Description
Title Optional page title. The first heading in the Markdown content.
HtmlFragment The HTML fragment string generated from the Markdown text.
RelativePath Passed through form the input object, provided it exists.

Notes

The conversion to HTML fragments also includes:

  • Changing links to Markdown files to the corresponding Html files.

    [Hello World](Hello.md)
    

    becomes:

    <a href="Hello.html">
    
  • HTML encoding code blocks:

    
    ```xml
    <root>
        <thing/>
    </root>
    
    ```
    

    becomes

    <pre><code class="language-xml">&lt;root&gt;
        &lt;thing/&gt;
    &lt;/root&gt;
    
    </code></pre>
    

    which renders as

    <root>
        <thing/>
    </root>
    
    

Examples

EXAMPLE 1

Convert-MarkdownToHTMLFragment -Markdown '# Hello World'

Returns the HTML fragment object:

Name               Value
----               -----
HtmlFragment       <h1 id="hello-world">Hello World</h1>...
Title              Hello World

EXAMPLE 2

Get-Item -LiteralPath "Convert-MarkdownToHTML.md" | Convert-MarkdownToHTMLFragment

Reads the content of Markdown file Example.md and returns a Html fragment object.

Name               Value
----               -----
Title              Convert-MarkdownToHTML
HtmlFragment       <h1 id="convert-Markdowntohtml">Convert-MarkdownToHTML</h1>...
RelativePath       Convert-MarkdownToHTML.md

Related Links


Module: MarkDownToHTML; Version: 2.3.1; (c) 2018-2021 WetHat Lab. All rights reserved.