I'm successfully converting HTML to Markdown, but elements such as <span class="cmd"> are preserved and appear in the MD result.
Is there a way, perhaps by using templates or Pandoc scripting, to replace the <span> element with <strong> or even with asterisks during the HTML-to-Markdown conversion?
For example:
I want to replace
<span class="cmd">This content must be bold</span>
with
<strong>This content must be bold</strong>
or
*This content must be bold*
Thanks very much.
You could adapt this pandoc filter. Save this as cmd_italics.py and run pandoc myfile.html -o myfile.md -F cmd_italics.py
#!/usr/bin/env python
from pandocfilters import toJSONFilter, Strong
def cmd_italics(key, value, format, meta):
if key == 'Span':
[[ident, classes, kvs], contents] = value
for c in classes:
if c == "cmd":
return Strong(contents)
if __name__ == "__main__":
toJSONFilter(cmd_italics)
You will need the pandocfilter python library installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With