一千萬個為什麽

搜索

如何從Pandoc中獲取Pandoc?

我開始使用pandoc api編寫幾個程序,以 https:// johnmacfarlane .net/BayHac2014 /#/ the-pandoc-types ,但我無法將Pandoc從m Pandoc中分離出來。

module ImageAttr where
import Text.Pandoc.Builder
import Text.Pandoc.Generic
import Text.Pandoc.Definition
import Text.Pandoc.JSON
import qualified Data.Char as DataChar
import qualified Data.List as DataList
import Data.Either
import Text.Parsec as Parsec
import Text.Pandoc
import qualified Data.Text as T
import qualified Data.Text.IO as TIO

fromRight :: b -> Either a b -> b
fromRight _ (Right b) = b
fromRight b _         = b


fromLeft :: b -> Either b a -> b
fromLeft  _ (Left b)  = b
fromLeft  b _        = b


main :: IO ()
main = do
        result <- runIO $ do
            doc <- readMarkdown def (T.pack "[testing](url)")
            writeRST def doc
        x<-((handleError result))
        print x

輸出是字符串,但我需要pandoc ast以前它是PandocError Pandoc類型,而不是我得到“m Pandoc”。如何讓潘多克脫離“潘多克人”。

任何想法? 順便說一句,我是新的,仍然在學習haskell。

我收到錯誤消息:

ImageSizeModifer.hs:28:12:
    Couldn't match expected type ‘PandocIO a0’ with actual type ‘IO ()’
    In a stmt of a 'do' block: print ""
    In the second argument of ‘($)’, namely
      ‘do { doc <- readMarkdown def (T.pack "[testing](url)");
            print "" }’
Failed, modules loaded: none.
Prelude T>

我的問題是我需要Pandoc,但我不知道如何得到它?有新的PandocIO和PandocPure,我相信這些都是新的。

最佳答案

The new version of pandoc has readMarkdown :: PandocMonad m => ReaderOptions -> Text -> m Pandoc. This follows the usual mtl-style of specifying the constraints on the monad, instead of the actual monad.

這意味著要使用 readMarkdown ,您需要選擇一個滿足 PandocMonad 的特定 m 。您可以通過滾動到 PandocMonad Pandoc-Class.html#t:PandocMonad“rel =”noreferrer“>其文檔。在這種情況下,您會發現:

  • PandocMonad PandocPure maybe interesting
  • PandocMonad PandocIO maybe interesting
  • (MonadTrans t, PandocMonad m, Functor (t m), MonadError PandocError (t m), Monad (t m), Applicative (t m)) => PandocMonad (t m) - not interesting, requires another PandocMonad m
  • PandocMonad m => PandocMonad (ParsecT s st m) - not interesting, requires another PandocMonad m

現在,滾動過去定義 PandocPurePandocIO 的地方,您可以找到運行提取信息的方法:

將這兩個函數中的任何一個與 readMarkdown 結合使用,您可以獲得具體的 Either 類型。

runIO (readMarkdown def (T.pack "[testing](url)")) :: IO (Either PandocError Pandoc)
runPure (readMarkdown def (T.pack "[testing](url)")) :: Either PandocError Pandoc

請註意,我對Pandoc或它的API一無所知 - 我所做的只是完成上述過程。

轉載註明原文: 如何從Pandoc中獲取Pandoc?