2016-11-26 14:46:28 +01:00
|
|
|
{-# LANGUAGE ScopedTypeVariables, FlexibleInstances, GADTs #-}
|
2007-11-04 00:27:58 +01:00
|
|
|
{-
|
2016-03-23 01:20:39 +01:00
|
|
|
Copyright (C) 2006-2016 John MacFarlane <jgm@berkeley.edu>
|
2007-11-04 00:27:58 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc
|
2016-03-23 01:20:39 +01:00
|
|
|
Copyright : Copyright (C) 2006-2016 John MacFarlane
|
2011-02-15 19:40:50 +01:00
|
|
|
License : GNU GPL, version 2 or above
|
2007-11-04 00:27:58 +01:00
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
2011-02-15 19:40:50 +01:00
|
|
|
Stability : alpha
|
2007-11-04 00:27:58 +01:00
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
This helper module exports the main writers, readers, and data
|
|
|
|
structure definitions from the Pandoc libraries.
|
|
|
|
|
|
|
|
A typical application will chain together a reader and a writer
|
|
|
|
to convert strings from one format to another. For example, the
|
|
|
|
following simple program will act as a filter converting markdown
|
|
|
|
fragments to reStructuredText, using reference-style links instead of
|
|
|
|
inline links:
|
|
|
|
|
|
|
|
> module Main where
|
|
|
|
> import Text.Pandoc
|
2008-08-01 01:16:31 +02:00
|
|
|
>
|
2016-12-03 22:35:58 +01:00
|
|
|
> markdownToRST :: String -> Either PandocError String
|
2016-10-23 21:48:22 +02:00
|
|
|
> markdownToRST =
|
2016-12-03 22:35:58 +01:00
|
|
|
> writeRST def {writerReferenceLinks = True} . readMarkdown def
|
2011-02-15 19:40:50 +01:00
|
|
|
>
|
2016-12-03 22:35:58 +01:00
|
|
|
> main = getContents >>= either error return markdownToRST >>= putStrLn
|
2007-11-04 00:27:58 +01:00
|
|
|
|
2009-10-05 00:09:23 +02:00
|
|
|
Note: all of the readers assume that the input text has @'\n'@
|
|
|
|
line endings. So if you get your input text from a web form,
|
|
|
|
you should remove @'\r'@ characters using @filter (/='\r')@.
|
|
|
|
|
2007-11-04 00:27:58 +01:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Text.Pandoc
|
2011-02-15 19:40:50 +01:00
|
|
|
(
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Definitions
|
|
|
|
module Text.Pandoc.Definition
|
2010-12-24 22:39:27 +01:00
|
|
|
-- * Generics
|
|
|
|
, module Text.Pandoc.Generic
|
2012-07-25 19:45:45 +02:00
|
|
|
-- * Options
|
|
|
|
, module Text.Pandoc.Options
|
2016-11-27 11:51:40 +01:00
|
|
|
-- * Typeclass
|
2016-12-10 23:14:43 +01:00
|
|
|
, PandocMonad
|
|
|
|
, runIO
|
|
|
|
, runPure
|
|
|
|
, runIOorExplode
|
2016-10-24 22:31:36 +02:00
|
|
|
-- * Error handling
|
|
|
|
, module Text.Pandoc.Error
|
2010-12-11 02:30:32 +01:00
|
|
|
-- * Lists of readers and writers
|
|
|
|
, readers
|
2016-11-26 14:46:28 +01:00
|
|
|
-- , writers
|
2016-11-27 06:05:53 +01:00
|
|
|
, writers
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Readers: converting /to/ Pandoc format
|
2014-06-15 14:38:16 +02:00
|
|
|
, Reader (..)
|
2014-06-17 07:44:40 +02:00
|
|
|
, readDocx
|
2015-07-23 09:06:14 +02:00
|
|
|
, readOdt
|
2007-11-04 00:27:58 +01:00
|
|
|
, readMarkdown
|
2015-03-17 06:20:42 +01:00
|
|
|
, readCommonMark
|
2012-09-10 19:02:12 +02:00
|
|
|
, readMediaWiki
|
2007-11-04 00:27:58 +01:00
|
|
|
, readRST
|
2014-03-04 00:33:25 +01:00
|
|
|
, readOrg
|
2007-11-04 00:27:58 +01:00
|
|
|
, readLaTeX
|
|
|
|
, readHtml
|
2010-09-16 11:26:12 +02:00
|
|
|
, readTextile
|
2012-05-13 04:29:39 +02:00
|
|
|
, readDocBook
|
2013-03-18 01:43:51 +01:00
|
|
|
, readOPML
|
2013-03-28 22:53:10 +01:00
|
|
|
, readHaddock
|
2011-01-20 17:52:11 +01:00
|
|
|
, readNative
|
2013-07-24 07:31:50 +02:00
|
|
|
, readJSON
|
2014-07-07 20:21:38 +02:00
|
|
|
, readTWiki
|
2014-07-14 00:38:22 +02:00
|
|
|
, readTxt2Tags
|
2014-07-30 01:57:20 +02:00
|
|
|
, readEPUB
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Writers: converting /from/ Pandoc format
|
2016-11-27 06:05:53 +01:00
|
|
|
, Writer(..)
|
2010-07-04 22:55:48 +02:00
|
|
|
, writeNative
|
2013-07-24 07:31:50 +02:00
|
|
|
, writeJSON
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeMarkdown
|
2010-03-18 07:45:43 +01:00
|
|
|
, writePlain
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeRST
|
|
|
|
, writeLaTeX
|
|
|
|
, writeConTeXt
|
2008-02-24 06:48:41 +01:00
|
|
|
, writeTexinfo
|
2017-01-25 21:51:26 +01:00
|
|
|
, writeHtml4
|
|
|
|
, writeHtml4String
|
|
|
|
, writeHtml5
|
|
|
|
, writeHtml5String
|
2017-01-27 22:39:36 +01:00
|
|
|
, writeRevealJs
|
|
|
|
, writeS5
|
|
|
|
, writeSlidy
|
|
|
|
, writeSlideous
|
|
|
|
, writeDZSlides
|
2013-12-01 21:11:39 +01:00
|
|
|
, writeICML
|
2017-01-26 22:40:57 +01:00
|
|
|
, writeDocbook4
|
|
|
|
, writeDocbook5
|
2013-03-20 04:35:14 +01:00
|
|
|
, writeOPML
|
2008-03-19 19:45:51 +01:00
|
|
|
, writeOpenDocument
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeMan
|
2008-07-27 05:25:51 +02:00
|
|
|
, writeMediaWiki
|
2013-07-14 14:40:27 +02:00
|
|
|
, writeDokuWiki
|
2016-06-29 08:11:42 +02:00
|
|
|
, writeZimWiki
|
2010-04-10 21:38:07 +02:00
|
|
|
, writeTextile
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeRTF
|
2010-07-03 05:12:14 +02:00
|
|
|
, writeODT
|
2012-01-03 21:10:10 +01:00
|
|
|
, writeDocx
|
2017-01-26 20:39:32 +01:00
|
|
|
, writeEPUB2
|
|
|
|
, writeEPUB3
|
2011-02-15 19:40:50 +01:00
|
|
|
, writeFB2
|
2010-12-04 11:27:39 +01:00
|
|
|
, writeOrg
|
2011-11-19 06:09:23 +01:00
|
|
|
, writeAsciiDoc
|
2014-06-19 00:32:13 +02:00
|
|
|
, writeHaddock
|
2015-03-23 19:35:44 +01:00
|
|
|
, writeCommonMark
|
2013-04-03 06:08:38 +02:00
|
|
|
, writeCustom
|
2015-12-24 17:36:58 +01:00
|
|
|
, writeTEI
|
2009-12-31 02:10:57 +01:00
|
|
|
-- * Rendering templates and default templates
|
|
|
|
, module Text.Pandoc.Templates
|
2011-01-28 17:42:04 +01:00
|
|
|
-- * Miscellaneous
|
2012-08-10 04:11:19 +02:00
|
|
|
, getReader
|
2016-11-27 06:05:53 +01:00
|
|
|
, getWriter
|
2016-11-18 17:01:09 +01:00
|
|
|
, getDefaultExtensions
|
2015-10-10 22:42:02 +02:00
|
|
|
, pandocVersion
|
2007-11-04 00:27:58 +01:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Text.Pandoc.Definition
|
2010-12-24 22:39:27 +01:00
|
|
|
import Text.Pandoc.Generic
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Readers.Markdown
|
2015-03-17 06:20:42 +01:00
|
|
|
import Text.Pandoc.Readers.CommonMark
|
2012-09-10 19:02:12 +02:00
|
|
|
import Text.Pandoc.Readers.MediaWiki
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Readers.RST
|
2014-03-04 00:33:25 +01:00
|
|
|
import Text.Pandoc.Readers.Org
|
2012-04-15 01:44:21 +02:00
|
|
|
import Text.Pandoc.Readers.DocBook
|
2013-03-18 01:43:51 +01:00
|
|
|
import Text.Pandoc.Readers.OPML
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Readers.LaTeX
|
|
|
|
import Text.Pandoc.Readers.HTML
|
2010-09-16 11:26:12 +02:00
|
|
|
import Text.Pandoc.Readers.Textile
|
2011-01-20 03:36:27 +01:00
|
|
|
import Text.Pandoc.Readers.Native
|
2013-03-28 22:53:10 +01:00
|
|
|
import Text.Pandoc.Readers.Haddock
|
2014-07-07 20:21:38 +02:00
|
|
|
import Text.Pandoc.Readers.TWiki
|
2014-06-17 07:44:40 +02:00
|
|
|
import Text.Pandoc.Readers.Docx
|
2015-07-23 09:06:14 +02:00
|
|
|
import Text.Pandoc.Readers.Odt
|
2014-07-14 00:38:22 +02:00
|
|
|
import Text.Pandoc.Readers.Txt2Tags
|
2014-07-30 01:57:20 +02:00
|
|
|
import Text.Pandoc.Readers.EPUB
|
2010-07-04 22:55:48 +02:00
|
|
|
import Text.Pandoc.Writers.Native
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Writers.Markdown
|
2011-02-15 19:40:50 +01:00
|
|
|
import Text.Pandoc.Writers.RST
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Writers.LaTeX
|
|
|
|
import Text.Pandoc.Writers.ConTeXt
|
2008-02-24 06:48:41 +01:00
|
|
|
import Text.Pandoc.Writers.Texinfo
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Writers.HTML
|
2010-07-03 05:12:14 +02:00
|
|
|
import Text.Pandoc.Writers.ODT
|
2012-01-03 21:10:10 +01:00
|
|
|
import Text.Pandoc.Writers.Docx
|
2010-07-03 07:07:00 +02:00
|
|
|
import Text.Pandoc.Writers.EPUB
|
2011-02-15 19:40:50 +01:00
|
|
|
import Text.Pandoc.Writers.FB2
|
2013-12-01 21:11:39 +01:00
|
|
|
import Text.Pandoc.Writers.ICML
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Writers.Docbook
|
2013-03-20 04:35:14 +01:00
|
|
|
import Text.Pandoc.Writers.OPML
|
2008-03-19 19:45:51 +01:00
|
|
|
import Text.Pandoc.Writers.OpenDocument
|
2007-11-04 00:27:58 +01:00
|
|
|
import Text.Pandoc.Writers.Man
|
2011-02-15 19:40:50 +01:00
|
|
|
import Text.Pandoc.Writers.RTF
|
2008-07-27 05:25:51 +02:00
|
|
|
import Text.Pandoc.Writers.MediaWiki
|
2013-07-14 14:40:27 +02:00
|
|
|
import Text.Pandoc.Writers.DokuWiki
|
2016-06-29 08:11:42 +02:00
|
|
|
import Text.Pandoc.Writers.ZimWiki
|
2010-04-10 21:38:07 +02:00
|
|
|
import Text.Pandoc.Writers.Textile
|
2010-12-04 11:27:39 +01:00
|
|
|
import Text.Pandoc.Writers.Org
|
2011-11-19 06:09:23 +01:00
|
|
|
import Text.Pandoc.Writers.AsciiDoc
|
2014-06-19 00:32:13 +02:00
|
|
|
import Text.Pandoc.Writers.Haddock
|
2015-03-23 19:35:44 +01:00
|
|
|
import Text.Pandoc.Writers.CommonMark
|
2013-04-03 06:08:38 +02:00
|
|
|
import Text.Pandoc.Writers.Custom
|
2015-12-24 17:36:58 +01:00
|
|
|
import Text.Pandoc.Writers.TEI
|
2009-12-31 02:10:57 +01:00
|
|
|
import Text.Pandoc.Templates
|
2012-07-25 19:45:45 +02:00
|
|
|
import Text.Pandoc.Options
|
2016-11-30 19:26:32 +01:00
|
|
|
import Text.Pandoc.Shared (safeRead, mapLeft, pandocVersion)
|
2015-02-18 20:56:59 +01:00
|
|
|
import Text.Pandoc.Error
|
2016-12-10 23:14:43 +01:00
|
|
|
import Text.Pandoc.Class
|
2013-08-04 01:39:43 +02:00
|
|
|
import Data.Aeson
|
2013-05-09 19:38:11 +02:00
|
|
|
import qualified Data.ByteString.Lazy as BL
|
2014-04-28 05:56:50 +02:00
|
|
|
import Data.List (intercalate)
|
2012-08-09 16:42:40 +02:00
|
|
|
import Text.Parsec
|
2012-08-10 05:19:06 +02:00
|
|
|
import Text.Parsec.Error
|
2013-05-09 19:38:11 +02:00
|
|
|
import qualified Text.Pandoc.UTF8 as UTF8
|
2016-11-28 23:13:46 +01:00
|
|
|
import Control.Monad.Except (throwError)
|
2010-12-11 02:30:32 +01:00
|
|
|
|
2012-08-09 16:42:40 +02:00
|
|
|
parseFormatSpec :: String
|
2017-01-14 13:06:27 +01:00
|
|
|
-> Either ParseError (String, Extensions -> Extensions)
|
2012-08-09 16:42:40 +02:00
|
|
|
parseFormatSpec = parse formatSpec ""
|
|
|
|
where formatSpec = do
|
|
|
|
name <- formatName
|
|
|
|
extMods <- many extMod
|
2016-06-24 08:04:42 +02:00
|
|
|
return (name, \x -> foldl (flip ($)) x extMods)
|
2012-08-09 16:42:40 +02:00
|
|
|
formatName = many1 $ noneOf "-+"
|
|
|
|
extMod = do
|
|
|
|
polarity <- oneOf "-+"
|
2012-08-10 05:19:06 +02:00
|
|
|
name <- many $ noneOf "-+"
|
|
|
|
ext <- case safeRead ("Ext_" ++ name) of
|
2012-08-09 17:11:28 +02:00
|
|
|
Just n -> return n
|
2012-08-10 05:19:06 +02:00
|
|
|
Nothing
|
|
|
|
| name == "lhs" -> return Ext_literate_haskell
|
|
|
|
| otherwise -> fail $ "Unknown extension: " ++ name
|
2012-08-09 16:42:40 +02:00
|
|
|
return $ case polarity of
|
2017-01-14 13:06:27 +01:00
|
|
|
'-' -> disableExtension ext
|
|
|
|
_ -> enableExtension ext
|
2012-08-09 16:42:40 +02:00
|
|
|
|
2016-11-27 15:55:02 +01:00
|
|
|
-- TODO: when we get the PandocMonad stuff all sorted out,
|
|
|
|
-- we can simply these types considerably. Errors/MediaBag can be
|
|
|
|
-- part of the monad's internal state.
|
2016-11-28 23:13:46 +01:00
|
|
|
data Reader m = StringReader (ReaderOptions -> String -> m Pandoc)
|
|
|
|
| ByteStringReader (ReaderOptions -> BL.ByteString -> m Pandoc)
|
2014-06-15 14:38:16 +02:00
|
|
|
|
2016-11-28 23:13:46 +01:00
|
|
|
-- mkStringReader :: (ReaderOptions -> String -> Either PandocError Pandoc) -> Reader IO
|
|
|
|
-- mkStringReader r = StringReader (\o s -> return $ r o s)
|
2014-06-15 14:38:16 +02:00
|
|
|
|
2016-11-28 23:13:46 +01:00
|
|
|
-- mkStringReaderWithWarnings :: (ReaderOptions -> String -> Either PandocError (Pandoc, [String])) -> Reader IO
|
|
|
|
-- mkStringReaderWithWarnings r = StringReader $ \o s ->
|
|
|
|
-- case r o s of
|
|
|
|
-- Left err -> return $ Left err
|
|
|
|
-- Right (doc, warnings) -> do
|
|
|
|
-- mapM_ warn warnings
|
|
|
|
-- return (Right doc)
|
2014-12-05 23:21:19 +01:00
|
|
|
|
2016-11-28 23:13:46 +01:00
|
|
|
-- mkBSReader :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag)) -> Reader IO
|
|
|
|
-- mkBSReader r = ByteStringReader (\o s -> return $ r o s)
|
2014-06-15 14:38:16 +02:00
|
|
|
|
2016-11-28 23:13:46 +01:00
|
|
|
-- mkBSReaderWithWarnings :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag, [String])) -> Reader IO
|
|
|
|
-- mkBSReaderWithWarnings r = ByteStringReader $ \o s ->
|
|
|
|
-- case r o s of
|
|
|
|
-- Left err -> return $ Left err
|
|
|
|
-- Right (doc, mediaBag, warnings) -> do
|
|
|
|
-- mapM_ warn warnings
|
|
|
|
-- return $ Right (doc, mediaBag)
|
2016-03-12 16:24:39 +01:00
|
|
|
|
2010-12-11 02:30:32 +01:00
|
|
|
-- | Association list of formats and readers.
|
2016-11-28 23:13:46 +01:00
|
|
|
readers :: PandocMonad m => [(String, Reader m)]
|
2016-12-10 16:52:35 +01:00
|
|
|
readers = [ ("native" , StringReader readNative)
|
2016-11-28 23:13:46 +01:00
|
|
|
,("json" , StringReader $ \o s ->
|
|
|
|
case readJSON o s of
|
|
|
|
Right doc -> return doc
|
|
|
|
Left _ -> throwError $ PandocParseError "JSON parse error")
|
|
|
|
,("markdown" , StringReader readMarkdown)
|
|
|
|
,("markdown_strict" , StringReader readMarkdown)
|
|
|
|
,("markdown_phpextra" , StringReader readMarkdown)
|
|
|
|
,("markdown_github" , StringReader readMarkdown)
|
|
|
|
,("markdown_mmd", StringReader readMarkdown)
|
|
|
|
,("commonmark" , StringReader readCommonMark)
|
2016-12-03 19:07:45 +01:00
|
|
|
,("rst" , StringReader readRST)
|
2016-11-28 23:13:46 +01:00
|
|
|
,("mediawiki" , StringReader readMediaWiki)
|
|
|
|
,("docbook" , StringReader readDocBook)
|
|
|
|
,("opml" , StringReader readOPML)
|
|
|
|
,("org" , StringReader readOrg)
|
|
|
|
,("textile" , StringReader readTextile) -- TODO : textile+lhs
|
|
|
|
,("html" , StringReader readHtml)
|
|
|
|
,("latex" , StringReader readLaTeX)
|
|
|
|
,("haddock" , StringReader readHaddock)
|
|
|
|
,("twiki" , StringReader readTWiki)
|
|
|
|
,("docx" , ByteStringReader readDocx)
|
|
|
|
,("odt" , ByteStringReader readOdt)
|
2016-11-30 19:26:32 +01:00
|
|
|
,("t2t" , StringReader readTxt2Tags)
|
2016-11-28 23:13:46 +01:00
|
|
|
,("epub" , ByteStringReader readEPUB)
|
2013-07-24 07:31:50 +02:00
|
|
|
]
|
2010-12-11 02:30:32 +01:00
|
|
|
|
2016-11-27 06:05:53 +01:00
|
|
|
data Writer m = StringWriter (WriterOptions -> Pandoc -> m String)
|
|
|
|
| ByteStringWriter (WriterOptions -> Pandoc -> m BL.ByteString)
|
2011-01-23 02:52:25 +01:00
|
|
|
|
2012-07-25 04:05:38 +02:00
|
|
|
-- | Association list of formats and writers.
|
2016-11-27 06:05:53 +01:00
|
|
|
writers :: PandocMonad m => [ ( String, Writer m) ]
|
|
|
|
writers = [
|
|
|
|
("native" , StringWriter writeNative)
|
|
|
|
,("json" , StringWriter $ \o d -> return $ writeJSON o d)
|
|
|
|
,("docx" , ByteStringWriter writeDocx)
|
|
|
|
,("odt" , ByteStringWriter writeODT)
|
2017-01-26 20:39:32 +01:00
|
|
|
,("epub" , ByteStringWriter writeEPUB2)
|
|
|
|
,("epub2" , ByteStringWriter writeEPUB2)
|
|
|
|
,("epub3" , ByteStringWriter writeEPUB3)
|
2016-11-27 06:05:53 +01:00
|
|
|
,("fb2" , StringWriter writeFB2)
|
2017-01-25 21:51:26 +01:00
|
|
|
,("html" , StringWriter writeHtml5String)
|
|
|
|
,("html4" , StringWriter writeHtml4String)
|
|
|
|
,("html5" , StringWriter writeHtml5String)
|
2016-11-27 06:05:53 +01:00
|
|
|
,("icml" , StringWriter writeICML)
|
2017-01-27 22:39:36 +01:00
|
|
|
,("s5" , StringWriter writeS5)
|
|
|
|
,("slidy" , StringWriter writeSlidy)
|
|
|
|
,("slideous" , StringWriter writeSlideous)
|
|
|
|
,("dzslides" , StringWriter writeDZSlides)
|
|
|
|
,("revealjs" , StringWriter writeRevealJs)
|
2017-01-26 22:40:57 +01:00
|
|
|
,("docbook" , StringWriter writeDocbook5)
|
|
|
|
,("docbook4" , StringWriter writeDocbook4)
|
|
|
|
,("docbook5" , StringWriter writeDocbook5)
|
2016-11-27 06:05:53 +01:00
|
|
|
,("opml" , StringWriter writeOPML)
|
|
|
|
,("opendocument" , StringWriter writeOpenDocument)
|
|
|
|
,("latex" , StringWriter writeLaTeX)
|
|
|
|
,("beamer" , StringWriter $ \o ->
|
2012-07-25 04:05:38 +02:00
|
|
|
writeLaTeX o{ writerBeamer = True })
|
2016-11-27 06:05:53 +01:00
|
|
|
,("context" , StringWriter writeConTeXt)
|
|
|
|
,("texinfo" , StringWriter writeTexinfo)
|
|
|
|
,("man" , StringWriter writeMan)
|
|
|
|
,("markdown" , StringWriter writeMarkdown)
|
|
|
|
,("markdown_strict" , StringWriter writeMarkdown)
|
|
|
|
,("markdown_phpextra" , StringWriter writeMarkdown)
|
|
|
|
,("markdown_github" , StringWriter writeMarkdown)
|
|
|
|
,("markdown_mmd" , StringWriter writeMarkdown)
|
|
|
|
,("plain" , StringWriter writePlain)
|
|
|
|
,("rst" , StringWriter writeRST)
|
|
|
|
,("mediawiki" , StringWriter writeMediaWiki)
|
|
|
|
,("dokuwiki" , StringWriter writeDokuWiki)
|
|
|
|
,("zimwiki" , StringWriter writeZimWiki)
|
|
|
|
,("textile" , StringWriter writeTextile)
|
2016-12-03 17:10:50 +01:00
|
|
|
,("rtf" , StringWriter writeRTF)
|
2016-11-27 06:05:53 +01:00
|
|
|
,("org" , StringWriter writeOrg)
|
|
|
|
,("asciidoc" , StringWriter writeAsciiDoc)
|
|
|
|
,("haddock" , StringWriter writeHaddock)
|
|
|
|
,("commonmark" , StringWriter writeCommonMark)
|
|
|
|
,("tei" , StringWriter writeTEI)
|
2012-07-25 04:05:38 +02:00
|
|
|
]
|
2011-02-15 19:40:50 +01:00
|
|
|
|
2017-01-14 13:06:27 +01:00
|
|
|
getDefaultExtensions :: String -> Extensions
|
2012-08-10 07:30:44 +02:00
|
|
|
getDefaultExtensions "markdown_strict" = strictExtensions
|
2013-01-11 07:38:07 +01:00
|
|
|
getDefaultExtensions "markdown_phpextra" = phpMarkdownExtraExtensions
|
2013-01-16 17:52:54 +01:00
|
|
|
getDefaultExtensions "markdown_mmd" = multimarkdownExtensions
|
2013-01-11 19:10:50 +01:00
|
|
|
getDefaultExtensions "markdown_github" = githubMarkdownExtensions
|
2013-12-07 02:31:47 +01:00
|
|
|
getDefaultExtensions "markdown" = pandocExtensions
|
2015-06-28 05:18:42 +02:00
|
|
|
getDefaultExtensions "plain" = plainExtensions
|
2017-01-14 13:06:27 +01:00
|
|
|
getDefaultExtensions "org" = extensionsFromList
|
2017-01-14 18:27:06 +01:00
|
|
|
[Ext_citations,
|
|
|
|
Ext_auto_identifiers]
|
2017-01-14 13:06:27 +01:00
|
|
|
getDefaultExtensions "html" = extensionsFromList
|
|
|
|
[Ext_auto_identifiers,
|
|
|
|
Ext_native_divs,
|
|
|
|
Ext_native_spans]
|
2017-01-25 21:51:26 +01:00
|
|
|
getDefaultExtensions "html4" = getDefaultExtensions "html"
|
2014-08-09 06:04:25 +02:00
|
|
|
getDefaultExtensions "html5" = getDefaultExtensions "html"
|
2017-01-14 13:06:27 +01:00
|
|
|
getDefaultExtensions "epub" = extensionsFromList
|
|
|
|
[Ext_raw_html,
|
|
|
|
Ext_native_divs,
|
|
|
|
Ext_native_spans,
|
|
|
|
Ext_epub_html_exts]
|
2017-01-26 20:39:32 +01:00
|
|
|
getDefaultExtensions "epub2" = getDefaultExtensions "epub"
|
|
|
|
getDefaultExtensions "epub3" = getDefaultExtensions "epub"
|
2017-01-14 18:27:06 +01:00
|
|
|
getDefaultExtensions "latex" = extensionsFromList
|
|
|
|
[Ext_smart,
|
|
|
|
Ext_auto_identifiers]
|
|
|
|
getDefaultExtensions "context" = extensionsFromList
|
|
|
|
[Ext_smart,
|
|
|
|
Ext_auto_identifiers]
|
2017-01-14 21:00:22 +01:00
|
|
|
getDefaultExtensions "textile" = extensionsFromList
|
|
|
|
[Ext_old_dashes,
|
|
|
|
Ext_smart,
|
|
|
|
Ext_auto_identifiers]
|
2017-01-14 13:06:27 +01:00
|
|
|
getDefaultExtensions _ = extensionsFromList
|
|
|
|
[Ext_auto_identifiers]
|
2012-08-10 05:41:50 +02:00
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
-- | Retrieve reader based on formatSpec (format+extensions).
|
2016-11-28 23:13:46 +01:00
|
|
|
getReader :: PandocMonad m => String -> Either String (Reader m)
|
2012-08-10 04:11:19 +02:00
|
|
|
getReader s =
|
|
|
|
case parseFormatSpec s of
|
2015-11-22 16:37:51 +01:00
|
|
|
Left e -> Left $ intercalate "\n" [m | Message m <- errorMessages e]
|
2014-07-13 07:57:22 +02:00
|
|
|
Right (readerName, setExts) ->
|
2012-08-10 04:11:19 +02:00
|
|
|
case lookup readerName readers of
|
|
|
|
Nothing -> Left $ "Unknown reader: " ++ readerName
|
2014-06-15 14:38:16 +02:00
|
|
|
Just (StringReader r) -> Right $ StringReader $ \o ->
|
|
|
|
r o{ readerExtensions = setExts $
|
|
|
|
getDefaultExtensions readerName }
|
|
|
|
Just (ByteStringReader r) -> Right $ ByteStringReader $ \o ->
|
2012-08-10 04:11:19 +02:00
|
|
|
r o{ readerExtensions = setExts $
|
2012-08-10 05:41:50 +02:00
|
|
|
getDefaultExtensions readerName }
|
2012-08-10 04:11:19 +02:00
|
|
|
|
2016-11-27 06:05:53 +01:00
|
|
|
getWriter :: PandocMonad m => String -> Either String (Writer m)
|
|
|
|
getWriter s
|
2014-04-28 05:56:50 +02:00
|
|
|
= case parseFormatSpec s of
|
2015-11-22 16:37:51 +01:00
|
|
|
Left e -> Left $ intercalate "\n" [m | Message m <- errorMessages e]
|
2014-04-28 05:56:50 +02:00
|
|
|
Right (writerName, setExts) ->
|
2016-11-27 06:05:53 +01:00
|
|
|
case lookup writerName writers of
|
2014-04-28 05:56:50 +02:00
|
|
|
Nothing -> Left $ "Unknown writer: " ++ writerName
|
2016-11-27 06:05:53 +01:00
|
|
|
Just (StringWriter r) -> Right $ StringWriter $
|
2014-04-28 05:56:50 +02:00
|
|
|
\o -> r o{ writerExtensions = setExts $
|
|
|
|
getDefaultExtensions writerName }
|
2016-11-27 06:05:53 +01:00
|
|
|
Just (ByteStringWriter r) -> Right $ ByteStringWriter $
|
2014-04-28 05:56:50 +02:00
|
|
|
\o -> r o{ writerExtensions = setExts $
|
|
|
|
getDefaultExtensions writerName }
|
2012-01-24 20:50:35 +01:00
|
|
|
|
2015-02-18 20:56:59 +01:00
|
|
|
readJSON :: ReaderOptions -> String -> Either PandocError Pandoc
|
2016-12-01 18:13:51 +01:00
|
|
|
readJSON _ = mapLeft PandocParseError . eitherDecode' . UTF8.fromStringLazy
|
2013-05-09 19:38:11 +02:00
|
|
|
|
2013-07-24 07:31:50 +02:00
|
|
|
writeJSON :: WriterOptions -> Pandoc -> String
|
|
|
|
writeJSON _ = UTF8.toStringLazy . encode
|