Feb 152019
 

Updated 10 Feb 2020: Added EditPad

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.

Command line solution

I started with a PowerShell solution in Explorer, the same can be done using cmd. Shift+right-click on a folder in the explorer right pane gives the context menu option “Open PowerShell window here”.

By default input is interpreted as markdown, and output is HTML, I started with 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, use -f to convert f(rom) markdown without the smart option (the minus disables):

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"

PowerShell Function

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

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

But when you close the shell this 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 form 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 and save. Now every time you open PowerShell you can do:

pandocx "My Notes"

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

Automating with EditPad

My long-time Text editor, EditPad does syntax highlighting for Markdown. It also has an option to integrate tools which can be configured to just be available for certain files types like *.md. I have a Pandoc tool created with the following command line option:

"C:\Program Files\Pandoc\pandoc.exe" -s -f markdown-smart --quiet --ascii "%FILENAMENOEXT%.md" -o "%FILENAMENOEXT%.html"

This take the current active file and creates a HTML version of it in the same folder. Because I have the output set to quiet there is not popup command line, It also means that any errors will be swallowed; a typical Pandoc error can be that the source file is not UTF-8, but EditPad allows me to default an encoding type per file type so this potential error is a non issue.