简体   繁体   English

如何从Pandoc中获取Pandoc?

[英]How to get Pandoc from m Pandoc?

I started to write few programs using the pandoc api ,taking examples from , https://johnmacfarlane.net/BayHac2014/#/the-pandoc-types , But I am unable to isolate Pandoc from m 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

output is String but I need pandoc ast previously it was Either PandocError Pandoc type , instead I am getting "m Pandoc". 输出是String,但之前我需要pandoc,或者是PandocError Pandoc type,而是得到“ m Pandoc”。 How to get Pandoc out of "m Pandoc". 如何使Pandoc脱离“ m Pandoc”。

any Thought? 任何想法? By the way , I am new and still learning haskell. 顺便说一句,我是新手,还在学习haskell。

I am getting error message as : 我收到以下错误消息:

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>

My problem is I need Pandoc , but I have not much idea how to to get it ? 我的问题是我需要Pandoc,但是我不知道如何获得它? There are new PandocIO and PandocPure , I believe these are new. 有新的PandocIO和PandocPure,我相信它们是新的。

The new version of pandoc has readMarkdown :: PandocMonad m => ReaderOptions -> Text -> m Pandoc . 新版本的pandoc具有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. 这遵循通常的mtl -style,即在monad上指定约束,而不是实际的monad。

That means that to use readMarkdown , you need to pick a particular m satisfying PandocMonad . 这意味着,使用readMarkdown ,你需要选择一个特定的m满足PandocMonad You can find what instances PandocMonad has by scrolling to the "Instances" section of its doc . 您可以通过滚动到其doc的“实例”部分来找到PandocMonad的实例。 In this case, you find: 在这种情况下,您会发现:

  • PandocMonad PandocPure maybe interesting PandocMonad PandocPure可能很有趣
  • PandocMonad PandocIO maybe interesting PandocMonad PandocIO可能很有趣
  • (MonadTrans t, PandocMonad m, Functor (tm), MonadError PandocError (tm), Monad (tm), Applicative (tm)) => PandocMonad (tm) - not interesting, requires another PandocMonad m (MonadTrans t, PandocMonad m, Functor (tm), MonadError PandocError (tm), Monad (tm), Applicative (tm)) => PandocMonad (tm) -不有趣,需要另一个PandocMonad m
  • PandocMonad m => PandocMonad (ParsecT s st m) - not interesting, requires another PandocMonad m PandocMonad m => PandocMonad (ParsecT s st m) - PandocMonad m ,需要另一个PandocMonad m

Now, scrolling past where PandocPure and PandocIO are defined, you can find ways of running extracting information out of those: 现在,滚动到定义PandocPurePandocIO位置,您可以找到从中提取信息的方法:

Combining either of these functions with readMarkdown , you can get a concrete Either type. 将这些功能与readMarkdown结合使用,就可以得到一个具体的Either类型。

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

Note that I know nothing about Pandoc or its API - all I did was walk through the above process. 请注意,我对Pandoc或其API一无所知-我所做的只是完成上述过程。

请访问http://pandoc.org/using-the-pandoc-api.html ,以获取有关使用pandoc 2.x API的基本教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM