Pandoc is a good free and flexible tool for this kind of thing.
Here, for example, I have installed pandoc
https://pandoc.org/installing.html
checked its install location by entering the command which pandoc
in the shell, and copied the path to a KM variable,
Paste MD as setx italic.kmmacros (18.8 KB)
and then used the following incantation, which you could adjust or fine-tune,
Using the shell to:
- read the clipboard -from
markdown_mmd
-tohtml
with pandoc - search replace html emphasis tags to temporary nonsense strings
- read the result -from
html
-tomarkdown_strict
with pandoc (for setext headings) - search replace the temporary nonsense strings to underscores
"$KMVAR_pandoc" -f markdown_mmd -t html | sed 's|<em>|~~start~~|g' | sed 's|</em>|~~end~~|g' | "$KMVAR_pandoc" -f html -t markdown_strict | sed 's|~~start~~|_|g' | sed 's|~~end~~|_|g'