Convert html mathjax to markdown with pandoc

删除回忆录丶 提交于 2019-12-20 06:44:17

问题


I have some html files including mathjax commands. I would like to translate it into php extra markdown using pandoc.

The problem is that pandoc add "\" before all math commands. For example \begin{equation} \$ x\^2 etc

Do you know how to avoid that with pandoc ? I think a related question is this one : How to convert HTML with mathjax into latex using pandoc?


回答1:


You can write a short Haskell program unescape.hs:

-- Disable backslash escaping of special characters when writing strings to markdown.
import Text.Pandoc

main = toJsonFilter unescape
  where unescape (Str xs) = RawInline "markdown" xs
        unescape x        = x

Now compile with ghc --make unescape.hs. And use with

pandoc -f html -t json | ./unescape | pandoc -f json -t markdown

This will disable escaping of special characters (like $) in markdown output.

A simpler approach might be to pipe pandoc's normal markdown output through sed:

pandoc -f html -t markdown | sed -e 's/\\\([$^_*]\)/\1/g'


来源:https://stackoverflow.com/questions/16014717/convert-html-mathjax-to-markdown-with-pandoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!