Convert Markdown to HTML using PowerShell

This short article will describe how to convert Markdown documents into HTML, a common task required by those who use the Markdown language to create documents. This language was invented a while back to allow the easy creation of email and web pages using a text-like syntax called Markdown. Since then, many libraries have been created to handle this type of conversion. Today we will use a .NET library to do this task.

1. Get the module

You will need the POSH-Markdown module for this code to work. All you need are the 2 DLL files available on GitHub here: https://github.com/jeffa00/posh-markdown/tree/master/powershellMarkdown/bin/Debug

2. Import the module

Once the files are downloaded, right click on them and select Properties. Select to Unblock them so they can be loaded in your script. Then, create the folder PowershellMarkdown under Documents -> WindowsPowershell -> Modules and place the files in there.

Now you can import the module:

Import-Module PowershellMarkdown
**
**

3. Converting a file

For this you will need a Markdown file. You can create it yourself or search the Internet for one. Then, you just need to load its content and call the convert method:

$c = Get-Content .\test.md
ConvertFrom-Markdown -MarkdownContent ($c -join "`n") | Out-File .\test.html

That's it!