2012-01-24 18:06:19 +01:00
|
|
|
{-# LANGUAGE ScopedTypeVariables, FlexibleInstances #-}
|
2007-11-04 00:27:58 +01:00
|
|
|
{-
|
2015-04-26 19:18:29 +02:00
|
|
|
Copyright (C) 2006-2015 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
|
2015-04-26 19:18:29 +02:00
|
|
|
Copyright : Copyright (C) 2006-2015 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
|
2015-03-28 21:37:18 +01:00
|
|
|
> import Text.Pandoc.Error (handleError)
|
2008-08-01 01:16:31 +02:00
|
|
|
>
|
2007-11-04 00:27:58 +01:00
|
|
|
> markdownToRST :: String -> String
|
2015-03-28 21:37:18 +01:00
|
|
|
> markdownToRST = handleError .
|
|
|
|
> writeRST def {writerReferenceLinks = True} .
|
|
|
|
> readMarkdown def
|
2011-02-15 19:40:50 +01:00
|
|
|
>
|
2009-12-31 17:48:21 +01:00
|
|
|
> main = getContents >>= putStrLn . markdownToRST
|
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
|
2010-12-11 02:30:32 +01:00
|
|
|
-- * Lists of readers and writers
|
|
|
|
, readers
|
|
|
|
, writers
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Readers: converting /to/ Pandoc format
|
2014-06-15 14:38:16 +02:00
|
|
|
, Reader (..)
|
2014-07-20 18:00:38 +02:00
|
|
|
, mkStringReader
|
2014-06-17 07:44:40 +02:00
|
|
|
, readDocx
|
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
|
|
|
|
, readTxt2TagsNoMacros
|
2014-07-30 01:57:20 +02:00
|
|
|
, readEPUB
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Writers: converting /from/ Pandoc format
|
2012-07-25 04:05:38 +02: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
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeHtml
|
|
|
|
, writeHtmlString
|
2013-12-01 21:11:39 +01:00
|
|
|
, writeICML
|
2007-11-04 00:27:58 +01:00
|
|
|
, writeDocbook
|
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
|
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
|
2013-01-05 22:00:12 +01:00
|
|
|
, writeEPUB
|
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
|
2009-12-31 02:10:57 +01:00
|
|
|
-- * Rendering templates and default templates
|
|
|
|
, module Text.Pandoc.Templates
|
2007-11-04 00:27:58 +01:00
|
|
|
-- * Version
|
|
|
|
, pandocVersion
|
2011-01-28 17:42:04 +01:00
|
|
|
-- * Miscellaneous
|
2012-08-10 04:11:19 +02:00
|
|
|
, getReader
|
|
|
|
, getWriter
|
2012-01-24 18:06:19 +01:00
|
|
|
, ToJsonFilter(..)
|
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
|
2013-08-04 01:39:43 +02:00
|
|
|
import Text.Pandoc.JSON
|
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
|
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
|
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
|
2009-12-31 02:10:57 +01:00
|
|
|
import Text.Pandoc.Templates
|
2012-07-25 19:45:45 +02:00
|
|
|
import Text.Pandoc.Options
|
2015-02-18 22:05:47 +01:00
|
|
|
import Text.Pandoc.Shared (safeRead, warn, mapLeft)
|
2014-07-31 21:00:21 +02:00
|
|
|
import Text.Pandoc.MediaBag (MediaBag)
|
2015-02-18 20:56:59 +01:00
|
|
|
import Text.Pandoc.Error
|
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)
|
2009-04-18 18:15:56 +02:00
|
|
|
import Data.Version (showVersion)
|
2012-08-09 16:42:40 +02:00
|
|
|
import Data.Set (Set)
|
|
|
|
import qualified Data.Set as Set
|
|
|
|
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
|
2009-04-18 18:15:56 +02:00
|
|
|
import Paths_pandoc (version)
|
2007-11-04 00:27:58 +01:00
|
|
|
|
|
|
|
-- | Version number of pandoc library.
|
|
|
|
pandocVersion :: String
|
2009-04-18 18:15:56 +02:00
|
|
|
pandocVersion = showVersion version
|
2010-12-11 02:30:32 +01:00
|
|
|
|
2012-08-09 16:42:40 +02:00
|
|
|
parseFormatSpec :: String
|
|
|
|
-> Either ParseError (String, Set Extension -> Set Extension)
|
|
|
|
parseFormatSpec = parse formatSpec ""
|
|
|
|
where formatSpec = do
|
|
|
|
name <- formatName
|
|
|
|
extMods <- many extMod
|
|
|
|
return (name, foldl (.) id extMods)
|
|
|
|
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
|
|
|
|
'-' -> Set.delete ext
|
|
|
|
_ -> Set.insert ext
|
|
|
|
|
2014-06-15 14:38:16 +02:00
|
|
|
|
2015-02-18 20:56:59 +01:00
|
|
|
data Reader = StringReader (ReaderOptions -> String -> IO (Either PandocError Pandoc))
|
|
|
|
| ByteStringReader (ReaderOptions -> BL.ByteString -> IO (Either PandocError (Pandoc,MediaBag)))
|
|
|
|
|
|
|
|
mkStringReader :: (ReaderOptions -> String -> (Either PandocError Pandoc)) -> Reader
|
2014-06-15 14:38:16 +02:00
|
|
|
mkStringReader r = StringReader (\o s -> return $ r o s)
|
|
|
|
|
2015-02-18 20:56:59 +01:00
|
|
|
mkStringReaderWithWarnings :: (ReaderOptions -> String -> Either PandocError (Pandoc, [String])) -> Reader
|
2014-12-05 23:21:19 +01:00
|
|
|
mkStringReaderWithWarnings r = StringReader $ \o s -> do
|
2015-02-18 20:56:59 +01:00
|
|
|
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
|
|
|
|
2015-02-18 20:56:59 +01:00
|
|
|
mkBSReader :: (ReaderOptions -> BL.ByteString -> (Either PandocError (Pandoc, MediaBag))) -> Reader
|
2014-06-15 14:38:16 +02:00
|
|
|
mkBSReader r = ByteStringReader (\o s -> return $ r o s)
|
|
|
|
|
2010-12-11 02:30:32 +01:00
|
|
|
-- | Association list of formats and readers.
|
2014-06-15 14:38:16 +02:00
|
|
|
readers :: [(String, Reader)]
|
|
|
|
readers = [ ("native" , StringReader $ \_ s -> return $ readNative s)
|
|
|
|
,("json" , mkStringReader readJSON )
|
2014-12-05 23:21:19 +01:00
|
|
|
,("markdown" , mkStringReaderWithWarnings readMarkdownWithWarnings)
|
|
|
|
,("markdown_strict" , mkStringReaderWithWarnings readMarkdownWithWarnings)
|
|
|
|
,("markdown_phpextra" , mkStringReaderWithWarnings readMarkdownWithWarnings)
|
|
|
|
,("markdown_github" , mkStringReaderWithWarnings readMarkdownWithWarnings)
|
|
|
|
,("markdown_mmd", mkStringReaderWithWarnings readMarkdownWithWarnings)
|
2015-03-17 06:20:42 +01:00
|
|
|
,("commonmark" , mkStringReader readCommonMark)
|
2014-12-05 23:21:19 +01:00
|
|
|
,("rst" , mkStringReaderWithWarnings readRSTWithWarnings )
|
2014-06-15 14:38:16 +02:00
|
|
|
,("mediawiki" , mkStringReader readMediaWiki)
|
|
|
|
,("docbook" , mkStringReader readDocBook)
|
|
|
|
,("opml" , mkStringReader readOPML)
|
|
|
|
,("org" , mkStringReader readOrg)
|
|
|
|
,("textile" , mkStringReader readTextile) -- TODO : textile+lhs
|
|
|
|
,("html" , mkStringReader readHtml)
|
|
|
|
,("latex" , mkStringReader readLaTeX)
|
|
|
|
,("haddock" , mkStringReader readHaddock)
|
2014-07-07 20:21:38 +02:00
|
|
|
,("twiki" , mkStringReader readTWiki)
|
2014-06-17 07:44:40 +02:00
|
|
|
,("docx" , mkBSReader readDocx)
|
2014-07-20 18:00:38 +02:00
|
|
|
,("t2t" , mkStringReader readTxt2TagsNoMacros)
|
2014-07-30 01:57:20 +02:00
|
|
|
,("epub" , mkBSReader readEPUB)
|
2013-07-24 07:31:50 +02:00
|
|
|
]
|
2010-12-11 02:30:32 +01:00
|
|
|
|
2012-07-25 04:05:38 +02:00
|
|
|
data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
|
|
|
|
| IOStringWriter (WriterOptions -> Pandoc -> IO String)
|
2013-08-04 01:39:43 +02:00
|
|
|
| IOByteStringWriter (WriterOptions -> Pandoc -> IO BL.ByteString)
|
2011-01-23 02:52:25 +01:00
|
|
|
|
2012-07-25 04:05:38 +02:00
|
|
|
-- | Association list of formats and writers.
|
|
|
|
writers :: [ ( String, Writer ) ]
|
|
|
|
writers = [
|
|
|
|
("native" , PureStringWriter writeNative)
|
2013-07-24 07:31:50 +02:00
|
|
|
,("json" , PureStringWriter writeJSON)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("docx" , IOByteStringWriter writeDocx)
|
2013-07-24 07:31:50 +02:00
|
|
|
,("odt" , IOByteStringWriter writeODT)
|
|
|
|
,("epub" , IOByteStringWriter $ \o ->
|
2013-05-11 07:53:35 +02:00
|
|
|
writeEPUB o{ writerEpubVersion = Just EPUB2 })
|
2013-07-24 07:31:50 +02:00
|
|
|
,("epub3" , IOByteStringWriter $ \o ->
|
2013-01-05 22:00:12 +01:00
|
|
|
writeEPUB o{ writerEpubVersion = Just EPUB3 })
|
2012-07-25 04:05:38 +02:00
|
|
|
,("fb2" , IOStringWriter writeFB2)
|
|
|
|
,("html" , PureStringWriter writeHtmlString)
|
|
|
|
,("html5" , PureStringWriter $ \o ->
|
|
|
|
writeHtmlString o{ writerHtml5 = True })
|
2013-12-01 21:11:39 +01:00
|
|
|
,("icml" , PureStringWriter writeICML)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("s5" , PureStringWriter $ \o ->
|
|
|
|
writeHtmlString o{ writerSlideVariant = S5Slides
|
|
|
|
, writerTableOfContents = False })
|
|
|
|
,("slidy" , PureStringWriter $ \o ->
|
|
|
|
writeHtmlString o{ writerSlideVariant = SlidySlides })
|
|
|
|
,("slideous" , PureStringWriter $ \o ->
|
|
|
|
writeHtmlString o{ writerSlideVariant = SlideousSlides })
|
|
|
|
,("dzslides" , PureStringWriter $ \o ->
|
|
|
|
writeHtmlString o{ writerSlideVariant = DZSlides
|
|
|
|
, writerHtml5 = True })
|
2013-03-24 02:46:27 +01:00
|
|
|
,("revealjs" , PureStringWriter $ \o ->
|
2013-03-20 21:59:47 +01:00
|
|
|
writeHtmlString o{ writerSlideVariant = RevealJsSlides
|
|
|
|
, writerHtml5 = True })
|
2012-07-25 04:05:38 +02:00
|
|
|
,("docbook" , PureStringWriter writeDocbook)
|
2013-03-20 04:35:14 +01:00
|
|
|
,("opml" , PureStringWriter writeOPML)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("opendocument" , PureStringWriter writeOpenDocument)
|
|
|
|
,("latex" , PureStringWriter writeLaTeX)
|
|
|
|
,("beamer" , PureStringWriter $ \o ->
|
|
|
|
writeLaTeX o{ writerBeamer = True })
|
|
|
|
,("context" , PureStringWriter writeConTeXt)
|
|
|
|
,("texinfo" , PureStringWriter writeTexinfo)
|
|
|
|
,("man" , PureStringWriter writeMan)
|
|
|
|
,("markdown" , PureStringWriter writeMarkdown)
|
2012-08-10 07:30:44 +02:00
|
|
|
,("markdown_strict" , PureStringWriter writeMarkdown)
|
2013-01-11 07:43:02 +01:00
|
|
|
,("markdown_phpextra" , PureStringWriter writeMarkdown)
|
2013-01-11 19:10:50 +01:00
|
|
|
,("markdown_github" , PureStringWriter writeMarkdown)
|
2013-01-16 17:52:54 +01:00
|
|
|
,("markdown_mmd" , PureStringWriter writeMarkdown)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("plain" , PureStringWriter writePlain)
|
|
|
|
,("rst" , PureStringWriter writeRST)
|
|
|
|
,("mediawiki" , PureStringWriter writeMediaWiki)
|
2013-07-14 14:40:27 +02:00
|
|
|
,("dokuwiki" , PureStringWriter writeDokuWiki)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("textile" , PureStringWriter writeTextile)
|
2013-01-18 19:33:37 +01:00
|
|
|
,("rtf" , IOStringWriter writeRTFWithEmbeddedImages)
|
2012-07-25 04:05:38 +02:00
|
|
|
,("org" , PureStringWriter writeOrg)
|
|
|
|
,("asciidoc" , PureStringWriter writeAsciiDoc)
|
2014-06-19 00:32:13 +02:00
|
|
|
,("haddock" , PureStringWriter writeHaddock)
|
2015-03-23 19:35:44 +01:00
|
|
|
,("commonmark" , PureStringWriter writeCommonMark)
|
2012-07-25 04:05:38 +02:00
|
|
|
]
|
2011-02-15 19:40:50 +01:00
|
|
|
|
2012-08-10 05:41:50 +02:00
|
|
|
getDefaultExtensions :: String -> Set Extension
|
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
|
2014-05-14 14:49:30 +02:00
|
|
|
getDefaultExtensions "org" = Set.fromList [Ext_citations]
|
2014-08-14 18:49:31 +02:00
|
|
|
getDefaultExtensions "textile" = Set.fromList [Ext_auto_identifiers]
|
2014-08-09 06:04:25 +02:00
|
|
|
getDefaultExtensions "html" = Set.fromList [Ext_auto_identifiers,
|
|
|
|
Ext_native_divs,
|
|
|
|
Ext_native_spans]
|
|
|
|
getDefaultExtensions "html5" = getDefaultExtensions "html"
|
|
|
|
getDefaultExtensions "epub" = Set.fromList [Ext_auto_identifiers,
|
|
|
|
Ext_raw_html,
|
|
|
|
Ext_native_divs,
|
|
|
|
Ext_native_spans,
|
|
|
|
Ext_epub_html_exts]
|
2013-12-07 02:31:47 +01:00
|
|
|
getDefaultExtensions _ = Set.fromList [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).
|
2014-06-15 14:38:16 +02:00
|
|
|
getReader :: String -> Either String Reader
|
2012-08-10 04:11:19 +02:00
|
|
|
getReader s =
|
|
|
|
case parseFormatSpec s of
|
2012-08-10 05:19:06 +02: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
|
|
|
|
|
|
|
-- | Retrieve writer based on formatSpec (format+extensions).
|
|
|
|
getWriter :: String -> Either String Writer
|
2014-04-28 05:56:50 +02:00
|
|
|
getWriter s
|
|
|
|
= case parseFormatSpec s of
|
|
|
|
Left e -> Left $ intercalate "\n" $ [m | Message m <- errorMessages e]
|
|
|
|
Right (writerName, setExts) ->
|
|
|
|
case lookup writerName writers of
|
|
|
|
Nothing -> Left $ "Unknown writer: " ++ writerName
|
|
|
|
Just (PureStringWriter r) -> Right $ PureStringWriter $
|
|
|
|
\o -> r o{ writerExtensions = setExts $
|
|
|
|
getDefaultExtensions writerName }
|
|
|
|
Just (IOStringWriter r) -> Right $ IOStringWriter $
|
|
|
|
\o -> r o{ writerExtensions = setExts $
|
|
|
|
getDefaultExtensions writerName }
|
|
|
|
Just (IOByteStringWriter r) -> Right $ IOByteStringWriter $
|
|
|
|
\o -> r o{ writerExtensions = setExts $
|
|
|
|
getDefaultExtensions writerName }
|
2012-01-24 20:50:35 +01:00
|
|
|
|
2013-08-04 02:02:35 +02:00
|
|
|
{-# DEPRECATED toJsonFilter "Use 'toJSONFilter' from 'Text.Pandoc.JSON' instead" #-}
|
|
|
|
-- | Deprecated. Use @toJSONFilter@ from @Text.Pandoc.JSON@ instead.
|
2013-08-04 01:39:43 +02:00
|
|
|
class ToJSONFilter a => ToJsonFilter a
|
|
|
|
where toJsonFilter :: a -> IO ()
|
|
|
|
toJsonFilter = toJSONFilter
|
2012-01-24 20:50:35 +01:00
|
|
|
|
2015-02-18 20:56:59 +01:00
|
|
|
readJSON :: ReaderOptions -> String -> Either PandocError Pandoc
|
|
|
|
readJSON _ = mapLeft ParseFailure . 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
|