git.iko.soy/typeable/pandoc
on master help sign in
Moved BlockWrapper and wrappedBlocksToDoc from ConTeXt writer to Shared.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1242 788f1e2b-df1e-0410-8736-df70ead52e1b

commit270eb7bed422ea5e742937fcd24933ffe8033fb4 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 24 Feb 2008, 05:48 (19 years ago) parent3d4d897
2 files changed+13−9
Text/Pandoc/Shared.hs+13−1 Text/Pandoc/Writers/ConTeXt.hs−8
Text/Pandoc/Shared.hs+13−1
@@ -47,6 +47,8 @@ module Text.Pandoc.Shared (
4747 wrapIfNeeded,
4848 wrappedTeX,
4949 wrapTeXIfNeeded,
50+ BlockWrapper (..),
51+ wrappedBlocksToDoc,
5052 -- * Parsing
5153 (>>~),
5254 anyLine,
@@ -101,7 +103,7 @@ module Text.Pandoc.Shared (
101103
102104import Text.Pandoc.Definition
103105import Text.ParserCombinators.Parsec
104−import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty )
106+import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text )
105107import qualified Text.PrettyPrint.HughesPJ as PP
106108import Text.Pandoc.CharacterReferences ( characterReference )
107109import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
@@ -262,6 +264,16 @@ wrapTeXIfNeeded opts includePercent = if writerWrapText opts
262264 then wrappedTeX includePercent
263265 else ($)
264266
267+-- | Indicates whether block should be surrounded by blank lines (@Pad@) or not (@Reg@).
268+data BlockWrapper = Pad Doc | Reg Doc
269+
270+-- | Converts a list of wrapped blocks to a Doc, with appropriate spaces around blocks.
271+wrappedBlocksToDoc :: [BlockWrapper] -> Doc
272+wrappedBlocksToDoc = foldr addBlock empty
273+ where addBlock (Pad d) accum | isEmpty accum = d
274+ addBlock (Pad d) accum = d $$ text "" $$ accum
275+ addBlock (Reg d) accum = d $$ accum
276+
265277--
266278-- Parsing
267279--
Text/Pandoc/Writers/ConTeXt.hs−8
@@ -41,8 +41,6 @@ data WriterState =
4141 , stOptions :: WriterOptions -- writer options
4242 }
4343
44−data BlockWrapper = Pad Doc | Reg Doc
45−
4644orderedListStyles = cycle ["[n]","[a]", "[r]", "[g]"]
4745
4846-- | Convert Pandoc to ConTeXt.
@@ -229,12 +227,6 @@ defListItemToConTeXt (term, def) = do
229227 def' <- blockListToConTeXt def
230228 return $ Pad $ text "\\startdescr{" <> term' <> char '}' $$ def' $$ text "\\stopdescr"
231229
232−wrappedBlocksToDoc :: [BlockWrapper] -> Doc
233−wrappedBlocksToDoc = foldr addBlock empty
234− where addBlock (Pad d) accum | isEmpty accum = d
235− addBlock (Pad d) accum = d $$ text "" $$ accum
236− addBlock (Reg d) accum = d $$ accum
237−
238230-- | Convert list of block elements to ConTeXt.
239231blockListToConTeXt :: [Block] -> State WriterState Doc
240232blockListToConTeXt lst = mapM blockToConTeXt lst >>= return . wrappedBlocksToDoc