PowerShell has two built-in cmdlets for working with Markdown files. No external tools required.
Show-Markdown
Show-Markdown renders a Markdown file directly in the terminal with color formatting:
Show-Markdown .\README.md
Headings, bold, italic, code blocks, and lists are all styled using VT100 escape sequences. It reads the file and prints formatted output inline.
You can also pipe a string:
"This is **bold**." | Show-Markdown
Open in the Browser
Pass -UseBrowser to render the Markdown as HTML and open it in your default browser:
Show-Markdown .\README.md -UseBrowser
PowerShell converts the file to HTML, writes it to a temp file, and launches the browser. Good for a quick formatted preview.
ConvertFrom-Markdown
ConvertFrom-Markdown parses a Markdown file and returns an object with both the HTML output and the abstract syntax tree:
$result = ConvertFrom-Markdown .\README.md
The object has two useful properties:
| Property | Description |
|---|---|
Html |
The converted HTML string |
Ast |
The parsed Markdown abstract syntax tree |
To get the HTML:
$result.Html
Save HTML to a File
$result = ConvertFrom-Markdown .\README.md
$result.Html > output.html
Or as a one-liner:
(ConvertFrom-Markdown .\README.md).Html > output.html
Convert a String
You can convert a Markdown string directly by piping it:
"## Hello`nThis is a paragraph." | ConvertFrom-Markdown
Pass -AsVT100EncodedString to get a VT100-formatted string for terminal display instead of an object:
"## Hello`nThis is a paragraph." | ConvertFrom-Markdown -AsVT100EncodedString
Which One to Use
- Reading a Markdown file in the terminal:
Show-Markdown - Previewing in a browser:
Show-Markdown -UseBrowser - Converting to HTML for further use:
ConvertFrom-Markdown