The output from "pandoc -f markdown -t native" shell command differs from the results generated by Pandoc Haskell library

huangapple go评论65阅读模式
英文:

The output from "pandoc -f markdown -t native" shell command differs from the results generated by Pandoc Haskell library

问题

在执行以下命令时:

pandoc -f markdown example.md -t native

example.md 文件中的代码块:

$(λx.M)$

会生成:

[ Para [ Math InlineMath "(\955x.M)" ] ]

然而,下面的 Haskell 代码从相同的文件中读取:

module Main where

import Control.Monad
import Control.Monad.Catch
import Control.Monad.IO.Class
import qualified Data.Text.IO as TIO
import Text.Pandoc

main :: IO ()
main = 
  TIO.putStrLn 
    <<= 
      runIOorExplode (do
        markdownText <- liftIO $ TIO.readFile "example.md"
        doc <- readMarkdown def markdownText
        writeNative def doc
      )

并生成:

[ Para [ Str &quot;$(\955x.M)$&quot; ] ]

这里发生了什么?为什么数学块没有被解析为 Math 类型?

英文:

Executing the following command

pandoc -f markdown example.md -t native

on

example.md

$(λx.M)$

produces:

[ Para [ Math InlineMath &quot;(5x.M)&quot; ] ]

However, the following code reads from that same file:

module Main where

import Control.Monad
import Control.Monad.Catch
import Control.Monad.IO.Class
import qualified Data.Text.IO as TIO
import Text.Pandoc

main :: IO ()
main = 
  TIO.putStrLn 
    =&lt;&lt; 
      runIOorExplode (do
        markdownText &lt;- liftIO $ TIO.readFile &quot;example.md&quot;
        doc &lt;- readMarkdown def markdownText
        writeNative def doc
      )

and produces:

[ Para [ Str &quot;$(\955x.M)$&quot; ] ]

What's happening here ? Why isn't math blocks being parsed as Math types ?

答案1

得分: 3

Pandoc 允许启用或禁用其支持的各种格式的各种扩展功能。def 默认的扩展集仅包含适用于大多数格式的一些扩展功能。对于 Pandoc 的 Markdown,您将需要来自 Text.Pandoc.Extensions 模块的 pandocExtensions。修改读取器参数以使用这些扩展功能,并将修改后的选项作为第一个参数传递给 readMarkdown 应该会产生所需的结果。

英文:

Pandoc allows to enable or disable various extensions for the formats that it supports. The def default set of extensions contains only a few extensions that work with most formats. For pandoc's Markdown you'll need pandocExtensions from the Text.Pandoc.Extensions module. Modifying the reader args to use those, and passing the modified options as the first arg to readMarkdown should give the desired result.

huangapple
  • 本文由 发表于 2023年5月18日 01:17:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定