diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-02-24 05:48:31 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-02-24 05:48:31 +0000 |
commit | 270eb7bed422ea5e742937fcd24933ffe8033fb4 (patch) | |
tree | e28be6d5d97465336b514f24eefa7d4c2f0755c1 /Text/Pandoc | |
parent | 3d4d897a676bcea6a05ac130cb6cd4e5aec48049 (diff) | |
download | pandoc-270eb7bed422ea5e742937fcd24933ffe8033fb4.tar.gz |
Moved BlockWrapper and wrappedBlocksToDoc from ConTeXt writer to Shared.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1242 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text/Pandoc')
-rw-r--r-- | Text/Pandoc/Shared.hs | 14 | ||||
-rw-r--r-- | Text/Pandoc/Writers/ConTeXt.hs | 8 |
2 files changed, 13 insertions, 9 deletions
diff --git a/Text/Pandoc/Shared.hs b/Text/Pandoc/Shared.hs index 402fb7aa3..1731a7c7d 100644 --- a/Text/Pandoc/Shared.hs +++ b/Text/Pandoc/Shared.hs @@ -47,6 +47,8 @@ module Text.Pandoc.Shared ( wrapIfNeeded, wrappedTeX, wrapTeXIfNeeded, + BlockWrapper (..), + wrappedBlocksToDoc, -- * Parsing (>>~), anyLine, @@ -101,7 +103,7 @@ module Text.Pandoc.Shared ( import Text.Pandoc.Definition import Text.ParserCombinators.Parsec -import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty ) +import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text ) import qualified Text.PrettyPrint.HughesPJ as PP import Text.Pandoc.CharacterReferences ( characterReference ) import Data.Char ( toLower, toUpper, ord, isLower, isUpper ) @@ -262,6 +264,16 @@ wrapTeXIfNeeded opts includePercent = if writerWrapText opts then wrappedTeX includePercent else ($) +-- | Indicates whether block should be surrounded by blank lines (@Pad@) or not (@Reg@). +data BlockWrapper = Pad Doc | Reg Doc + +-- | Converts a list of wrapped blocks to a Doc, with appropriate spaces around blocks. +wrappedBlocksToDoc :: [BlockWrapper] -> Doc +wrappedBlocksToDoc = foldr addBlock empty + where addBlock (Pad d) accum | isEmpty accum = d + addBlock (Pad d) accum = d $$ text "" $$ accum + addBlock (Reg d) accum = d $$ accum + -- -- Parsing -- diff --git a/Text/Pandoc/Writers/ConTeXt.hs b/Text/Pandoc/Writers/ConTeXt.hs index cd1d09e0c..1695d70e7 100644 --- a/Text/Pandoc/Writers/ConTeXt.hs +++ b/Text/Pandoc/Writers/ConTeXt.hs @@ -41,8 +41,6 @@ data WriterState = , stOptions :: WriterOptions -- writer options } -data BlockWrapper = Pad Doc | Reg Doc - orderedListStyles = cycle ["[n]","[a]", "[r]", "[g]"] -- | Convert Pandoc to ConTeXt. @@ -229,12 +227,6 @@ defListItemToConTeXt (term, def) = do def' <- blockListToConTeXt def return $ Pad $ text "\\startdescr{" <> term' <> char '}' $$ def' $$ text "\\stopdescr" -wrappedBlocksToDoc :: [BlockWrapper] -> Doc -wrappedBlocksToDoc = foldr addBlock empty - where addBlock (Pad d) accum | isEmpty accum = d - addBlock (Pad d) accum = d $$ text "" $$ accum - addBlock (Reg d) accum = d $$ accum - -- | Convert list of block elements to ConTeXt. blockListToConTeXt :: [Block] -> State WriterState Doc blockListToConTeXt lst = mapM blockToConTeXt lst >>= return . wrappedBlocksToDoc |