Feb 152019
 

I regularly use “quotes” in my markdown .md files as well as the occasional currency symbol, e,g, €. I use Pandoc, a universal document converter, to convert my files to HTML from the PowerShell command line. In Explorer, shift+right-click on a folder in the right pane gives the context menu option “Open PowerShell window here”.

Since, by default, input is interpreted as markdown, and output as HTML, I was doing a simple:

pandoc "my notes.md" > "my notes.html"

But, the quotes and currency symbols were showing as ?Ç£ or ?Ç¥ or something. It turns out that Pandoc was converting the straight quotes into curly quotes, this is called the ‘smart’ option, which is enabled by default. The curly quotes were not appearing properly as my conversion above just creates a HTML fragment and a fragment doesn’t include the information that the text is UTF-8 encoded, which the browser needs to know to display it properly.

pandoc -s "my notes.md" > "my notes.html"

Using the -s option causes pandoc to emit a standalone HTML document with header which includes:

<meta charset="utf-8" />

To just use the straight quotes, convert f(rom) markdown without the smart option (- = minus, to disable):

pandoc -s -f markdown-smart "my notes.md" > "my notes.html"

I still had issues with the currency symbols. The –ascii option causes pandoc to emit entities instead of UTF-8 characters.

pandoc -s -f markdown-smart --ascii "My Notes.md" > "My notes.html"

This is not ideal to type for regular conversion. PowerShell has the option to add a function where you can pass arguments using $args. With PowerShell open, top create the function Pandocx, type:

function pandocx { pandoc -s -f markdown-smart --ascii "$args.md" > "$args.html" }

But when you close the shell the function pandocx is gone so to add it permanently you can add it to your profile. First you need to Run PowerShell as an administrator by right-clicking on it from the start menu. Now check your Execution Policies:

Get-ExecutionPolicy

By default it’s restricted, so you can do:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted 

Now, check if a profile exists by:

test-path $profile

If this returns false create one by:

new-item -path $profile -itemtype file -force

Now open the profile for editing in the Integrated Scripting Environment editor:

powershell_ise $profile

Add the function line for pandocx above and save. Now everytime you open PowerShell you can do:

pandocx "My Notes"

to convert your markdown file with quotes and symbols to HTML.