From 270eb7bed422ea5e742937fcd24933ffe8033fb4 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sun, 24 Feb 2008 05:48:31 +0000 Subject: Moved BlockWrapper and wrappedBlocksToDoc from ConTeXt writer to Shared. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1242 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Shared.hs | 14 +++++++++++++- 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 -- cgit v1.2.3