aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-05 00:49:53 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-05 00:49:53 +0100
commit33b4bc837196582956d8bd5538b6676be6a0f8e9 (patch)
treeffabb3bef3f7705853cf99ffa2ddb5daffc6a60f /src
parentbfa734c402fab970c1abebf1d6c1429f060082b8 (diff)
downloadpandoc-33b4bc837196582956d8bd5538b6676be6a0f8e9.tar.gz
Pretty: Added `afterBreak`.
This makes it possible to insert escape codes for content that needs escaping at the beginning of a line.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Pretty.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Pretty.hs b/src/Text/Pandoc/Pretty.hs
index b9f646282..256f38b0c 100644
--- a/src/Text/Pandoc/Pretty.hs
+++ b/src/Text/Pandoc/Pretty.hs
@@ -45,6 +45,7 @@ module Text.Pandoc.Pretty (
, hang
, beforeNonBlank
, nowrap
+ , afterBreak
, offset
, minOffset
, height
@@ -101,6 +102,7 @@ data D = Text Int String
| BeforeNonBlank Doc
| Flush Doc
| BreakingSpace
+ | AfterBreak String
| CarriageReturn
| NewLine
| BlankLines Int -- number of blank lines
@@ -306,6 +308,7 @@ renderList (BreakingSpace : BreakingSpace : xs) = renderList (BreakingSpace:xs)
renderList (BreakingSpace : xs) = do
let isText (Text _ _) = True
isText (Block _ _) = True
+ isText (AfterBreak _) = True
isText _ = False
let isBreakingSpace BreakingSpace = True
isBreakingSpace _ = False
@@ -321,6 +324,13 @@ renderList (BreakingSpace : xs) = do
outp 1 " "
renderList xs'
+renderList (AfterBreak s : xs) = do
+ st <- get
+ if newlines st > 0
+ then outp (realLength s) s
+ else return ()
+ renderList xs
+
renderList (Block i1 s1 : Block i2 s2 : xs) =
renderList (mergeBlocks False (IsBlock i1 s1) (IsBlock i2 s2) : xs)
@@ -422,6 +432,11 @@ nowrap doc = Doc $ mapWithIndex replaceSpace $ unDoc doc
where replaceSpace _ BreakingSpace = Text 1 " "
replaceSpace _ x = x
+-- | Content to print only if it comes at the beginning of a line,
+-- to be used e.g. for escaping line-initial `.` in groff man.
+afterBreak :: String -> Doc
+afterBreak s = Doc $ singleton (AfterBreak s)
+
-- | Returns the width of a 'Doc'.
offset :: Doc -> Int
offset d = case map realLength . lines . render Nothing $ d of