aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@gmail.com>2016-11-11 13:07:50 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:39 +0100
commit30b3412857fc604656aac53d57730ad2442a3599 (patch)
treef7ede52dbf2ef7e53e1eae7ae8c971dac86f9dd2 /src/Text/Pandoc/Writers
parent5a03ebf05b71b5e217110719dce03f09b4084d4f (diff)
downloadpandoc-30b3412857fc604656aac53d57730ad2442a3599.tar.gz
Added page breaks into Pandoc.
This requires an updated version of pandoc-types that introduces PageBreak definition. Not that this initial commit only introduces ODT pagebreaks and distinguishes for it page breaks before, after, or both, the paragraph, as read from the style definition.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 8f0e037c5..444a09587 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -36,6 +36,7 @@ import Text.Pandoc.XML
import Text.Pandoc.Shared (linesToPara)
import Text.Pandoc.Templates (renderTemplate')
import Text.Pandoc.Readers.TeXMath
+import Text.Pandoc.Readers.Odt.StyleReader
import Text.Pandoc.Pretty
import Text.Printf ( printf )
import Control.Arrow ( (***), (>>>) )
@@ -307,9 +308,7 @@ blockToOpenDocument o bs
else inParagraphTags =<< inlinesToOpenDocument o b
| Para [Image attr c (s,'f':'i':'g':':':t)] <- bs
= figure attr c s t
- | Para b <- bs = if null b
- then return empty
- else inParagraphTags =<< inlinesToOpenDocument o b
+ | Para b <- bs = paragraph b
| LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
| Div _ xs <- bs = blocksToOpenDocument o xs
| Header i _ b <- bs = setFirstPara >>
@@ -370,6 +369,22 @@ blockToOpenDocument o bs
captionDoc <- withParagraphStyle o "FigureCaption" [Para caption]
return $ imageDoc $$ captionDoc
+ endsWithPageBreak [] = False
+ endsWithPageBreak [PageBreak] = True
+ endsWithPageBreak (_ : xs) = endsWithPageBreak xs
+
+ paragraph :: [Inline] -> State WriterState Doc
+ paragraph [] = return empty
+ paragraph (PageBreak : rest) | endsWithPageBreak rest = paraWithBreak PageBoth rest
+ paragraph (PageBreak : rest) = paraWithBreak PageBefore rest
+ paragraph inlines | endsWithPageBreak inlines = paraWithBreak PageAfter inlines
+ paragraph inlines = inParagraphTags =<< inlinesToOpenDocument o inlines
+
+ paraWithBreak :: ParaBreak -> [Inline] -> State WriterState Doc
+ paraWithBreak breakKind bs = do
+ pn <- paraBreakStyle breakKind
+ withParagraphStyle o ("P" ++ show pn) [Para bs]
+
colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
colHeadsToOpenDocument o tn ns hs =
inTagsIndented "table:table-header-rows" . inTagsIndented "table:table-row" . vcat <$>
@@ -562,6 +577,13 @@ paraStyle attrs = do
addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) paraProps
return pn
+paraBreakStyle :: ParaBreak -> State WriterState Int
+paraBreakStyle PageBefore = paraStyle "Text_20_body" [("fo:break-before", "page")]
+paraBreakStyle PageAfter = paraStyle "Text_20_body" [("fo:break-after", "page")]
+paraBreakStyle PageBoth = paraStyle "Text_20_body" [("fo:break-before", "page"), ("fo:break-after", "page")]
+paraBreakStyle AutoNone = paraStyle "Text_20_body" []
+
+
paraListStyle :: Int -> State WriterState Int
paraListStyle l = paraStyle
[("style:parent-style-name","Text_20_body")