3
我試圖通過John MacFarlane here來實現Haskell解決方案,該解決方案允許我將帶有MathJax(latex)輸入的HTML文件轉換爲.tex,同時保留數學。該腳本是:無法編譯Haskell程序(「無法匹配」的錯誤)
import Text.Pandoc
main = toJsonFilter fixmath
fixmath :: Block -> Block
fixmath = bottomUp fixmathBlock . bottomUp fixmathInline
fixmathInline :: Inline -> Inline
fixmathInline (RawInline "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
RawInline "tex" $ take (length xs - 3) xs
fixmathInline x = x
fixmathBlock :: Block -> Block
fixmathBlock (RawBlock "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
RawBlock "tex" $ take (length xs - 3) xs
fixmathBlock x = x
我安裝哈斯克爾的64位OSX版本,並且也給了命令cabal install pandoc
得到pandoc功能。然而,在執行
ghc --make fixmath.hs
我得到以下錯誤:
[1 of 1] Compiling Main (fixmath.hs, fixmath.o)
fixmath.hs:9:26:
Couldn't match expected type `Format' with actual type `[Char]'
In the pattern: "html"
In the pattern:
RawInline "html"
('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
In an equation for `fixmathInline':
fixmathInline
(RawInline "html"
('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
= RawInline "tex" $ take (length xs - 3) xs
fixmath.hs:10:13:
Couldn't match expected type `Format' with actual type `[Char]'
In the first argument of `RawInline', namely `"tex"'
In the expression: RawInline "tex"
In the expression: RawInline "tex" $ take (length xs - 3) xs
fixmath.hs:14:24:
Couldn't match expected type `Format' with actual type `[Char]'
In the pattern: "html"
In the pattern:
RawBlock "html"
('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
In an equation for `fixmathBlock':
fixmathBlock
(RawBlock "html"
('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
= RawBlock "tex" $ take (length xs - 3) xs
fixmath.hs:15:12:
Couldn't match expected type `Format' with actual type `[Char]'
In the first argument of `RawBlock', namely `"tex"'
In the expression: RawBlock "tex"
In the expression: RawBlock "tex" $ take (length xs - 3) xs
什麼出了錯,我該怎麼辦?
感謝您的支持。它現在只返回一個(不同的)錯誤。我得到以下內容(抱歉格式化):_fixmath.hs:3:8:由於使用toJsonFilter而沒有實例(ToJsonFilter(Block - > Block))可能的修復:添加一個實例聲明(ToJsonFilter(Block-> Block))在表達式中:toJsonFilter fixmath在main的等式中:main = toJsonFilter fixmath_ – TSGM
這是由於我發佈該腳本後發生的另一個pandoc更改。嘗試使用'toJSONFilter'而不是'toJsonFilter'。 –
這似乎有訣竅,在代碼頂部增加了一個'import Text.Pandoc.JSON'。我不知道爲什麼我必須聲明第二個導入命令,但單個'import Text.Pandoc'仍然給我錯誤。 – TSGM