2

I use the following Powershell script to convert the raw Markdown-Plain-Text in my clipboard into pastable things that can be used in an arbitrary browser. I use it most heavily for writing emails in Gmail, and for Google Docs.

paste.exe | pandoc -f markdown -t HTML |  Set-Clipboard -AsHtml ; echo 'Conversion done.' 

It has been working amazingly well, except for its conversion of the closing double quotes.

  • When I type, I do not distinguish between the Opening and the Closing quotation marks;
  • Either, it is pandoc that wanted to help, but screw up a bit,
  • Or, it is the Set-Clipboard Powershell command that needs a bit more of attention.

Experts, please advise what "magic flag" to put, so that I can avoid manually cleaning up the �? markers all over the place.

llinfeng
  • 1,316
  • 1
  • 15
  • 39
  • `$(paste.exe) -replace '“','"' -replace '”','"'` _should_ translate all _Left_ and _Right_ Double Quotation Marks (`U+201C` and `U+201D`, respectively) to common ones `U+0022` (Unicode standard does not know terms _Opening_ and _Closing_ for quotation marks). – JosefZ Jan 28 '19 at 22:17
  • 1
    Note that `[console]::OutputEncoding` determines how PowerShell interprets the output from `paste.exe` and `pandoc` and, on sending `paste.exe` output to `pandoc`, PowerShell uses the encoding specified in preference variable `$OutputEncoding`, which, unfortunately, defaults to _ASCII_ in Windows Powershell; see also: https://stackoverflow.com/a/49481797/45375 – mklement0 Jan 29 '19 at 01:49

1 Answers1

2

You can disable Pandoc's smart extension, which is enabled by default for markdown, latex, and context output.

pandoc -f markdown-smart -t HTML

Note that you "disable" an extension by appending -EXTENSION to the format, where EXTENSION is the extension name. Therefore the format is markdown-smart. Conversely you can enable an extension with +EXTENSION. So you might read markdown-smart as "markdown minus smart".

As an aside, the name smart is likely borrowed from SmartyPants, a postprocessor to the original Markdown implementation which replaces straight quotes with curly quotes among other things. I found the extension by opening the Pandoc User Guide and searching for smart. Now you know. ;-)

Waylan
  • 37,164
  • 12
  • 83
  • 109
  • Great. For some reason, when I pass things through Powershell, it did not like `markdown-smart` as a whole. Instead, adding a space in between does the job like magic! The command that worked for me is: ` pandoc -f markdown -smart -t HTML `. [@Waylan, would you mind updating your post? It won't let me insert one extra character when editing on my side.] – llinfeng Jan 30 '19 at 01:53
  • no idea what powershell is doing, but the proper command is without the space. – mb21 Jan 30 '19 at 09:41
  • I'm not going to update my answer as that would make it wrong for most people. – Waylan Jan 30 '19 at 13:41
  • Confirm that nor does Powershell liked the space. My current setup uses exactly the same flags as you prescribed. Not sure why I needed a whitespace when I first tested the flags. – llinfeng Feb 11 '19 at 23:04
  • Update for the `markdown -smart` vs `markdown-smart`. The former is expected when I install Pandoc through `chocolatey` on a Windows 10 machine, through Admin-righted-PowerShell. Source: https://chocolatey.org/packages/pandoc – llinfeng Feb 27 '19 at 14:59
  • The error message it threw at me was: `pandoc.exe: Unknown extension: smart`. I happen to be running the conversion script through AutoHotKey, and I am not that interested to fix a pandoc flg issue ==> ended up adding conditional statements based on the machine-name to feed in the _locally correct_ set of flags. – llinfeng Feb 27 '19 at 15:08