{-# LANGUAGE ScopedTypeVariables, FlexibleInstances #-}{-
Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
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
Copyright : Copyright (C) 2006-2010 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
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
>
> markdownToRST :: String -> String
> markdownToRST =
> (writeRST def {writerReferenceLinks = True}) . readMarkdown def
>
> main = getContents >>= putStrLn . markdownToRST
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')@.
-}moduleText.Pandoc(-- * DefinitionsmoduleText.Pandoc.Definition-- * Generics,moduleText.Pandoc.Generic-- * Options,moduleText.Pandoc.Options-- * Lists of readers and writers,readers,writers-- * Readers: converting /to/ Pandoc format,readMarkdown,readMediaWiki,readRST,readLaTeX,readHtml,readTextile,readDocBook,readOPML,readHaddock,readNative,readJSON-- * Writers: converting /from/ Pandoc format,Writer(..),writeNative,writeJSON,writeMarkdown,writePlain,writeRST,writeLaTeX,writeConTeXt,writeTexinfo,writeHtml,writeHtmlString,writeDocbook,writeOPML,writeOpenDocument,writeMan,writeMediaWiki,writeTextile,writeRTF,writeODT,writeDocx,writeEPUB,writeFB2,writeOrg,writeAsciiDoc,writeCustom-- * Rendering templates and default templates,moduleText.Pandoc.Templates-- * Version,pandocVersion-- * Miscellaneous,getReader,getWriter,ToJsonFilter(..))whereimportText.Pandoc.DefinitionimportText.Pandoc.GenericimportText.Pandoc.JSONimportText.Pandoc.Readers.MarkdownimportText.Pandoc.Readers.MediaWikiimportText.Pandoc.Readers.RSTimportText.Pandoc.Readers.DocBookimportText.Pandoc.Readers.OPMLimportText.Pandoc.Readers.LaTeXimportText.Pandoc.Readers.HTMLimportText.Pandoc.Readers.TextileimportText.Pandoc.Readers.NativeimportText.Pandoc.Readers.HaddockimportText.Pandoc.Writers.NativeimportText.Pandoc.Writers.MarkdownimportText.Pandoc.Writers.RSTimportText.Pandoc.Writers.LaTeXimportText.Pandoc.Writers.ConTeXtimportText.Pandoc.Writers.TexinfoimportText.Pandoc.Writers.HTMLimportText.Pandoc.Writers.ODTimportText.Pandoc.Writers.DocximportText.Pandoc.Writers.EPUBimportText.Pandoc.Writers.FB2importText.Pandoc.Writers.DocbookimportText.Pandoc.Writers.OPMLimportText.Pandoc.Writers.OpenDocumentimportText.Pandoc.Writers.ManimportText.Pandoc.Writers.RTFimportText.Pandoc.Writers.MediaWikiimportText.Pandoc.Writers.TextileimportText.Pandoc.Writers.OrgimportText.Pandoc.Writers.AsciiDocimportText.Pandoc.Writers.CustomimportText.Pandoc.TemplatesimportText.Pandoc.OptionsimportText.Pandoc.Shared(safeRead,warn)importData.AesonimportqualifiedData.ByteString.LazyasBLimportData.List(intercalate,isSuffixOf)importData.Version(showVersion)importData.Set(Set)importqualifiedData.SetasSetimportText.ParsecimportText.Parsec.ErrorimportqualifiedText.Pandoc.UTF8asUTF8importPaths_pandoc(version)-- | Version number of pandoc library.pandocVersion::StringpandocVersion=showVersionversionparseFormatSpec::String->EitherParseError(String,SetExtension->SetExtension)parseFormatSpec=parseformatSpec""whereformatSpec=doname<-formatNameextMods<-manyextModreturn(name,foldl(.)idextMods)formatName=many1$noneOf"-+"extMod=dopolarity<-oneOf"-+"name<-many$noneOf"-+"ext<-casesafeRead("Ext_"++name)ofJustn->returnnNothing|name=="lhs"->returnExt_literate_haskell|otherwise->fail$"Unknown extension: "++namereturn$casepolarityof'-'->Set.deleteext_->Set.insertext-- auxiliary function for readers:markdown::ReaderOptions->String->IOPandocmarkdownos=dolet(doc,warnings)=readMarkdownWithWarningsosmapM_warnwarningsreturndoc-- | Association list of formats and readers.readers::[(String,ReaderOptions->String->IOPandoc)]readers=[("native",\_s->return$readNatives),("json",\os->return$readJSONos),("markdown",markdown),("markdown_strict",markdown),("markdown_phpextra",markdown),("markdown_github",markdown),("markdown_mmd",markdown),("rst",\os->return$readRSTos),("mediawiki",\os->return$readMediaWikios),("docbook",\os->return$readDocBookos),("opml",\os->return$readOPMLos),("textile",\os->return$readTextileos)-- TODO : textile+lhs,("html",\os->return$readHtmlos),("latex",\os->return$readLaTeXos),("haddock",\os->return$readHaddockos)]dataWriter=PureStringWriter(WriterOptions->Pandoc->String)|IOStringWriter(WriterOptions->Pandoc->IOString)|IOByteStringWriter(WriterOptions->Pandoc->IOBL.ByteString)-- | Association list of formats and writers.writers::[(String,Writer)]writers=[("native",PureStringWriterwriteNative),("json",PureStringWriterwriteJSON),("docx",IOByteStringWriterwriteDocx),("odt",IOByteStringWriterwriteODT),("epub",IOByteStringWriter$\o->writeEPUBo{writerEpubVersion=JustEPUB2}),("epub3",IOByteStringWriter$\o->writeEPUBo{writerEpubVersion=JustEPUB3}),("fb2",IOStringWriterwriteFB2),("html",PureStringWriterwriteHtmlString),("html5",PureStringWriter$\o->writeHtmlStringo{writerHtml5=True}),("s5",PureStringWriter$\o->writeHtmlStringo{writerSlideVariant=S5Slides,writerTableOfContents=False}),("slidy",PureStringWriter$\o->writeHtmlStringo{writerSlideVariant=SlidySlides}),("slideous",PureStringWriter$\o->writeHtmlStringo{writerSlideVariant=SlideousSlides}),("dzslides",PureStringWriter$\o->writeHtmlStringo{writerSlideVariant=DZSlides,writerHtml5=True}),("revealjs",PureStringWriter$\o->writeHtmlStringo{writerSlideVariant=RevealJsSlides,writerHtml5=True}),("docbook",PureStringWriterwriteDocbook),("opml",PureStringWriterwriteOPML),("opendocument",PureStringWriterwriteOpenDocument),("latex",PureStringWriterwriteLaTeX),("beamer",PureStringWriter$\o->writeLaTeXo{writerBeamer=True}),("context",PureStringWriterwriteConTeXt),("texinfo",PureStringWriterwriteTexinfo),("man",PureStringWriterwriteMan),("markdown",PureStringWriterwriteMarkdown),("markdown_strict",PureStringWriterwriteMarkdown),("markdown_phpextra",PureStringWriterwriteMarkdown),("markdown_github",PureStringWriterwriteMarkdown),("markdown_mmd",PureStringWriterwriteMarkdown),("plain",PureStringWriterwritePlain),("rst",PureStringWriterwriteRST),("mediawiki",PureStringWriterwriteMediaWiki),("textile",PureStringWriterwriteTextile),("rtf",IOStringWriterwriteRTFWithEmbeddedImages),("org",PureStringWriterwriteOrg),("asciidoc",PureStringWriterwriteAsciiDoc)]getDefaultExtensions::String->SetExtensiongetDefaultExtensions"markdown_strict"=strictExtensionsgetDefaultExtensions"markdown_phpextra"=phpMarkdownExtraExtensionsgetDefaultExtensions"markdown_mmd"=multimarkdownExtensionsgetDefaultExtensions"markdown_github"=githubMarkdownExtensionsgetDefaultExtensions"markdown"=pandocExtensionsgetDefaultExtensions"plain"=pandocExtensionsgetDefaultExtensions"textile"=Set.fromList[Ext_auto_identifiers,Ext_raw_tex]getDefaultExtensions_=Set.fromList[Ext_auto_identifiers]-- | Retrieve reader based on formatSpec (format+extensions).getReader::String->EitherString(ReaderOptions->String->IOPandoc)getReaders=caseparseFormatSpecsofLefte->Left$intercalate"\n"$[m|Messagem<-errorMessagese]Right(readerName,setExts)->caselookupreaderNamereadersofNothing->Left$"Unknown reader: "++readerNameJustr->Right$\o->ro{readerExtensions=setExts$getDefaultExtensionsreaderName}-- | Retrieve writer based on formatSpec (format+extensions).getWriter::String->EitherStringWritergetWriters=caseparseFormatSpecsofLefte->Left$intercalate"\n"$[m|Messagem<-errorMessagese]Right(writerName,setExts)->caselookupwriterNamewritersofNothing|".lua"`isSuffixOf`s->Right$IOStringWriter$writeCustoms|otherwise->Left$"Unknown writer: "++writerNameJust(PureStringWriterr)->Right$PureStringWriter$\o->ro{writerExtensions=setExts$getDefaultExtensionswriterName}Just(IOStringWriterr)->Right$IOStringWriter$\o->ro{writerExtensions=setExts$getDefaultExtensionswriterName}Just(IOByteStringWriterr)->Right$IOByteStringWriter$\o->ro{writerExtensions=setExts$getDefaultExtensionswriterName}{-# DEPRECATED toJsonFilter "Use 'toJSONFilter' from 'Text.Pandoc.JSON' instead" #-}-- | Deprecated. Use @toJSONFilter@ from @Text.Pandoc.JSON@ instead.classToJSONFiltera=>ToJsonFilterawheretoJsonFilter::a->IO()toJsonFilter=toJSONFilterreadJSON::ReaderOptions->String->PandocreadJSON_=eithererrorid.eitherDecode'.UTF8.fromStringLazywriteJSON::WriterOptions->Pandoc->StringwriteJSON_=UTF8.toStringLazy.encode