diff options
author | TG <tarik.graba@telecom-paristech.fr> | 2019-02-05 19:12:48 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-02-09 08:21:53 -0800 |
commit | 568b25d33a277b02cddbe646f3d6ec31f00ec99b (patch) | |
tree | 529d6b8ae020dc44660efcbd443fbd52345a3e97 /src/Text | |
parent | 8fdeae2872d76e0d6cd996d595aa22d259074a91 (diff) | |
download | pandoc-568b25d33a277b02cddbe646f3d6ec31f00ec99b.tar.gz |
Adds Asciidoctor sprcific writer and tests
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/AsciiDoc.hs | 41 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Writers.hs b/src/Text/Pandoc/Writers.hs index 629dbf717..26318e191 100644 --- a/src/Text/Pandoc/Writers.hs +++ b/src/Text/Pandoc/Writers.hs @@ -37,6 +37,7 @@ module Text.Pandoc.Writers Writer(..) , writers , writeAsciiDoc + , writeAsciiDoctor , writeBeamer , writeCommonMark , writeConTeXt @@ -178,6 +179,7 @@ writers = [ ,("rtf" , TextWriter writeRTF) ,("org" , TextWriter writeOrg) ,("asciidoc" , TextWriter writeAsciiDoc) + ,("asciidoctor" , TextWriter writeAsciiDoctor) ,("haddock" , TextWriter writeHaddock) ,("commonmark" , TextWriter writeCommonMark) ,("gfm" , TextWriter writeCommonMark) diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs index c156a1908..a33fd8916 100644 --- a/src/Text/Pandoc/Writers/AsciiDoc.hs +++ b/src/Text/Pandoc/Writers/AsciiDoc.hs @@ -37,7 +37,7 @@ that it has omitted the construct. AsciiDoc: <http://www.methods.co.nz/asciidoc/> -} -module Text.Pandoc.Writers.AsciiDoc (writeAsciiDoc) where +module Text.Pandoc.Writers.AsciiDoc (writeAsciiDoc, writeAsciiDoctor) where import Prelude import Control.Monad.State.Strict import Data.Char (isPunctuation, isSpace, toLower) @@ -61,18 +61,27 @@ data WriterState = WriterState { defListMarker :: String , bulletListLevel :: Int , intraword :: Bool , autoIds :: Set.Set String + , asciidoctorVariant :: Bool } +defaultWriterState :: WriterState +defaultWriterState = WriterState { defListMarker = "::" + , orderedListLevel = 0 + , bulletListLevel = 0 + , intraword = False + , autoIds = Set.empty + , asciidoctorVariant = False + } + -- | Convert Pandoc to AsciiDoc. writeAsciiDoc :: PandocMonad m => WriterOptions -> Pandoc -> m Text writeAsciiDoc opts document = - evalStateT (pandocToAsciiDoc opts document) WriterState{ - defListMarker = "::" - , orderedListLevel = 0 - , bulletListLevel = 0 - , intraword = False - , autoIds = Set.empty - } + evalStateT (pandocToAsciiDoc opts document) defaultWriterState + +-- | Convert Pandoc to AsciiDoctor compatible AsciiDoc. +writeAsciiDoctor :: PandocMonad m => WriterOptions -> Pandoc -> m Text +writeAsciiDoctor opts document = + evalStateT (pandocToAsciiDoc opts document) defaultWriterState{ asciidoctorVariant = True } type ADW = StateT WriterState @@ -411,12 +420,20 @@ inlineToAsciiDoc opts (Quoted DoubleQuote lst) = inlineToAsciiDoc _ (Code _ str) = return $ text "`" <> text (escapeStringUsing (backslashEscapes "`") str) <> "`" inlineToAsciiDoc _ (Str str) = return $ text $ escapeString str -inlineToAsciiDoc _ (Math InlineMath str) = - return $ "latexmath:[$" <> text str <> "$]" -inlineToAsciiDoc _ (Math DisplayMath str) = +inlineToAsciiDoc _ (Math InlineMath str) = do + isAsciidoctor <- gets asciidoctorVariant + let content = if isAsciidoctor + then text str + else "$" <> text str <> "$" + return $ "latexmath:[" <> content <> "]" +inlineToAsciiDoc _ (Math DisplayMath str) = do + isAsciidoctor <- gets asciidoctorVariant + let content = if isAsciidoctor + then text str + else "\\[" <> text str <> "\\]" return $ blankline <> "[latexmath]" $$ "++++" $$ - "\\[" <> text str <> "\\]" + content $$ "++++" $$ blankline inlineToAsciiDoc _ il@(RawInline f s) | f == "asciidoc" = return $ text s |