git.iko.soy/typeable/pandoc
on master help sign in
Pretty: Added `afterBreak`.
33b4bc8John MacFarlane
src/Text/Pandoc/Pretty.hs+15
@@ -45,6 +45,7 @@ module Text.Pandoc.Pretty (
45 , hang
45 , hang
46 , beforeNonBlank
46 , beforeNonBlank
47 , nowrap
47 , nowrap
48+ , afterBreak
48 , offset
49 , offset
49 , minOffset
50 , minOffset
50 , height
51 , height
@@ -101,6 +102,7 @@ data D = Text Int String
101 | BeforeNonBlank Doc
102 | BeforeNonBlank Doc
102 | Flush Doc
103 | Flush Doc
103 | BreakingSpace
104 | BreakingSpace
105+ | AfterBreak String
104 | CarriageReturn
106 | CarriageReturn
105 | NewLine
107 | NewLine
106 | BlankLines Int -- number of blank lines
108 | BlankLines Int -- number of blank lines
@@ -306,6 +308,7 @@ renderList (BreakingSpace : BreakingSpace : xs) = renderList (BreakingSpace:xs)
306renderList (BreakingSpace : xs) = do
308renderList (BreakingSpace : xs) = do
307 let isText (Text _ _) = True
309 let isText (Text _ _) = True
308 isText (Block _ _) = True
310 isText (Block _ _) = True
311+ isText (AfterBreak _) = True
309 isText _ = False
312 isText _ = False
310 let isBreakingSpace BreakingSpace = True
313 let isBreakingSpace BreakingSpace = True
311 isBreakingSpace _ = False
314 isBreakingSpace _ = False
@@ -321,6 +324,13 @@ renderList (BreakingSpace : xs) = do
321 outp 1 " "
324 outp 1 " "
322 renderList xs'
325 renderList xs'
323
326
327+renderList (AfterBreak s : xs) = do
328+ st <- get
329+ if newlines st > 0
330+ then outp (realLength s) s
331+ else return ()
332+ renderList xs
333+
324renderList (Block i1 s1 : Block i2 s2 : xs) =
334renderList (Block i1 s1 : Block i2 s2 : xs) =
325 renderList (mergeBlocks False (IsBlock i1 s1) (IsBlock i2 s2) : xs)
335 renderList (mergeBlocks False (IsBlock i1 s1) (IsBlock i2 s2) : xs)
326
336
@@ -422,6 +432,11 @@ nowrap doc = Doc $ mapWithIndex replaceSpace $ unDoc doc
422 where replaceSpace _ BreakingSpace = Text 1 " "
432 where replaceSpace _ BreakingSpace = Text 1 " "
423 replaceSpace _ x = x
433 replaceSpace _ x = x
424
434
435+-- | Content to print only if it comes at the beginning of a line,
436+-- to be used e.g. for escaping line-initial `.` in groff man.
437+afterBreak :: String -> Doc
438+afterBreak s = Doc $ singleton (AfterBreak s)
439+
425-- | Returns the width of a 'Doc'.
440-- | Returns the width of a 'Doc'.
426offset :: Doc -> Int
441offset :: Doc -> Int
427offset d = case map realLength . lines . render Nothing $ d of
442offset d = case map realLength . lines . render Nothing $ d of