【问题标题】:Convert html mathjax to markdown with pandoc使用 pandoc 将 html mathjax 转换为 markdown
【发布时间】:2013-04-07 12:57:45
【问题描述】:

我有一些 html 文件,包括 mathjax 命令。 我想用 pandoc 把它翻译成 php extra markdown。

问题是 pandoc 在所有数学命令之前添加“\”。例如 \开始{方程} \$ x\^2 等等

您知道如何使用 pandoc 避免这种情况吗? 我认为一个相关的问题是这个:How to convert HTML with mathjax into latex using pandoc?

【问题讨论】:

    标签: html mathjax pandoc


    【解决方案1】:

    你可以编写一个简短的 Haskell 程序 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
    

    现在用ghc --make unescape.hs 编译。并与

    一起使用
    pandoc -f html -t json | ./unescape | pandoc -f json -t markdown
    

    这将禁用 markdown 输出中特殊字符(如 $)的转义。

    更简单的方法可能是通过 sed 管道 pandoc 的正常降价输出:

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

    【讨论】:

    • 感谢您的回答。简单的正则表达式似乎工作正常。但是,如果将 markdown 与 mathjax 一起使用,则转义 asterix 可能很有用,例如使用 \begin{align*}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2021-07-15
    • 2019-04-23
    • 2016-10-08
    • 2021-05-26
    相关资源
    最近更新 更多