git.iko.soy/typeable/pandoc
on master help sign in
Added page breaks into Pandoc.
30b3412Hubert Plociniczak
src/Text/Pandoc/Readers/Odt/ContentReader.hs+15−4
@@ -381,9 +381,9 @@ getParaModifier :: Style -> ParaModifier
381getParaModifier Style{..} | Just props <- paraProperties styleProperties
381getParaModifier Style{..} | Just props <- paraProperties styleProperties
382 , isBlockQuote (indentation props)
382 , isBlockQuote (indentation props)
383 (margin_left props)
383 (margin_left props)
384− = blockQuote
384+ = pageBreakMaybe (paraProperties styleProperties) blockQuote
385 | otherwise
385 | otherwise
386− = id
386+ = pageBreakMaybe (paraProperties styleProperties) id
387 where
387 where
388 isBlockQuote mIndent mMargin
388 isBlockQuote mIndent mMargin
389 | LengthValueMM indent <- mIndent
389 | LengthValueMM indent <- mIndent
@@ -408,7 +408,19 @@ getParaModifier Style{..} | Just props <- paraProperties styleProperties
408
408
409 | otherwise
409 | otherwise
410 = False
410 = False
411−
411+ pageBreakMaybe :: Maybe ParaProperties -> ParaModifier -> ParaModifier
412+ pageBreakMaybe (Just props) modifier = insertPageBreak (page_break props) modifier
413+ pageBreakMaybe Nothing modifier = modifier
414+
415+ insertPageBreak :: ParaBreak -> ParaModifier -> ParaModifier
416+ insertPageBreak PageAfter modifier =
417+ \x -> (fromList (toList (modifier x) ++ [Para (toList pageBreak)]))
418+ insertPageBreak PageBefore modifier =
419+ \x -> (fromList (Para (toList pageBreak) : toList (modifier x)))
420+ insertPageBreak PageBoth modifier =
421+ \x -> (fromList ((Para (toList pageBreak) : toList (modifier x)) ++ [Para (toList pageBreak)]))
422+ insertPageBreak _ modifier =
423+ modifier
412--
424--
413constructPara :: OdtReaderSafe Blocks Blocks -> OdtReaderSafe Blocks Blocks
425constructPara :: OdtReaderSafe Blocks Blocks -> OdtReaderSafe Blocks Blocks
414constructPara reader = proc blocks -> do
426constructPara reader = proc blocks -> do
@@ -894,7 +906,6 @@ read_reference_ref = matchingElement NsText "reference-ref"
894 $ maybeInAnchorRef
906 $ maybeInAnchorRef
895 <<< matchChildContent [] read_plain_text
907 <<< matchChildContent [] read_plain_text
896
908
897−
898----------------------
909----------------------
899-- Entry point
910-- Entry point
900----------------------
911----------------------
src/Text/Pandoc/Readers/Odt/StyleReader.hs+21−6
@@ -43,6 +43,7 @@ module Text.Pandoc.Readers.Odt.StyleReader
43, TextProperties (..)
43, TextProperties (..)
44, ParaProperties (..)
44, ParaProperties (..)
45, VerticalTextPosition (..)
45, VerticalTextPosition (..)
46+, ParaBreak (..)
46, ListItemNumberFormat (..)
47, ListItemNumberFormat (..)
47, ListLevel
48, ListLevel
48, ListStyle (..)
49, ListStyle (..)
@@ -273,6 +274,7 @@ instance Default TextProperties where
273data ParaProperties = PropP { paraNumbering :: ParaNumbering
274data ParaProperties = PropP { paraNumbering :: ParaNumbering
274 , indentation :: LengthOrPercent
275 , indentation :: LengthOrPercent
275 , margin_left :: LengthOrPercent
276 , margin_left :: LengthOrPercent
277+ , page_break :: ParaBreak
276 }
278 }
277 deriving ( Eq, Show )
279 deriving ( Eq, Show )
278
280
@@ -280,6 +282,7 @@ instance Default ParaProperties where
280 def = PropP { paraNumbering = NumberingNone
282 def = PropP { paraNumbering = NumberingNone
281 , indentation = def
283 , indentation = def
282 , margin_left = def
284 , margin_left = def
285+ , page_break = AutoNone
283 }
286 }
284
287
285----
288----
@@ -314,6 +317,9 @@ instance Lookupable UnderlineMode where
314data ParaNumbering = NumberingNone | NumberingKeep | NumberingRestart Int
317data ParaNumbering = NumberingNone | NumberingKeep | NumberingRestart Int
315 deriving ( Eq, Show )
318 deriving ( Eq, Show )
316
319
320+data ParaBreak = AutoNone | PageBefore | PageAfter | PageBoth
321+ deriving ( Eq, Show )
322+
317data LengthOrPercent = LengthValueMM Int | PercentValue Int
323data LengthOrPercent = LengthValueMM Int | PercentValue Int
318 deriving ( Eq, Show )
324 deriving ( Eq, Show )
319
325
@@ -533,16 +539,20 @@ readLineMode modeAttr styleAttr = proc x -> do
533readParaProperties :: StyleReader _x ParaProperties
539readParaProperties :: StyleReader _x ParaProperties
534readParaProperties =
540readParaProperties =
535 executeIn NsStyle "paragraph-properties" $ liftAsSuccess
541 executeIn NsStyle "paragraph-properties" $ liftAsSuccess
536− ( liftA3 PropP
542+ ( liftA4 PropP
537 ( liftA2 readNumbering
543 ( liftA2 readNumbering
538− ( isSet' NsText "number-lines" )
544+ ( isSet' NsText "number-lines" )
539− ( readAttr' NsText "line-number" )
545+ ( readAttr' NsText "line-number" )
540 )
546 )
541 ( liftA2 readIndentation
547 ( liftA2 readIndentation
542− ( isSetWithDefault NsStyle "auto-text-indent" False )
548+ ( isSetWithDefault NsStyle "auto-text-indent" False )
543− ( getAttr NsXSL_FO "text-indent" )
549+ ( getAttr NsXSL_FO "text-indent" )
550+ )
551+ ( getAttr NsXSL_FO "margin-left" )
552+ ( liftA2 readPageBreak
553+ ( findAttrWithDefault NsXSL_FO "break-before" "auto" )
554+ ( findAttrWithDefault NsXSL_FO "break-after" "auto" )
544 )
555 )
545− ( getAttr NsXSL_FO "margin-left" )
546 )
556 )
547 where readNumbering (Just True) (Just n) = NumberingRestart n
557 where readNumbering (Just True) (Just n) = NumberingRestart n
548 readNumbering (Just True) _ = NumberingKeep
558 readNumbering (Just True) _ = NumberingKeep
@@ -551,6 +561,11 @@ readParaProperties =
551 readIndentation False indent = indent
561 readIndentation False indent = indent
552 readIndentation True _ = def
562 readIndentation True _ = def
553
563
564+ readPageBreak "page" "page" = PageBoth
565+ readPageBreak "page" _ = PageBefore
566+ readPageBreak _ "page" = PageAfter
567+ readPageBreak _ _ = AutoNone
568+
554----
569----
555-- List styles
570-- List styles
556----
571----
src/Text/Pandoc/Writers/OpenDocument.hs+25−3
@@ -36,6 +36,7 @@ import Text.Pandoc.XML
36import Text.Pandoc.Shared (linesToPara)
36import Text.Pandoc.Shared (linesToPara)
37import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Templates (renderTemplate')
38import Text.Pandoc.Readers.TeXMath
38import Text.Pandoc.Readers.TeXMath
39+import Text.Pandoc.Readers.Odt.StyleReader
39import Text.Pandoc.Pretty
40import Text.Pandoc.Pretty
40import Text.Printf ( printf )
41import Text.Printf ( printf )
41import Control.Arrow ( (***), (>>>) )
42import Control.Arrow ( (***), (>>>) )
@@ -307,9 +308,7 @@ blockToOpenDocument o bs
307 else inParagraphTags =<< inlinesToOpenDocument o b
308 else inParagraphTags =<< inlinesToOpenDocument o b
308 | Para [Image attr c (s,'f':'i':'g':':':t)] <- bs
309 | Para [Image attr c (s,'f':'i':'g':':':t)] <- bs
309 = figure attr c s t
310 = figure attr c s t
310− | Para b <- bs = if null b
311+ | Para b <- bs = paragraph b
311− then return empty
312− else inParagraphTags =<< inlinesToOpenDocument o b
313 | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
312 | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
314 | Div _ xs <- bs = blocksToOpenDocument o xs
313 | Div _ xs <- bs = blocksToOpenDocument o xs
315 | Header i _ b <- bs = setFirstPara >>
314 | Header i _ b <- bs = setFirstPara >>
@@ -370,6 +369,22 @@ blockToOpenDocument o bs
370 captionDoc <- withParagraphStyle o "FigureCaption" [Para caption]
369 captionDoc <- withParagraphStyle o "FigureCaption" [Para caption]
371 return $ imageDoc $$ captionDoc
370 return $ imageDoc $$ captionDoc
372
371
372+ endsWithPageBreak [] = False
373+ endsWithPageBreak [PageBreak] = True
374+ endsWithPageBreak (_ : xs) = endsWithPageBreak xs
375+
376+ paragraph :: [Inline] -> State WriterState Doc
377+ paragraph [] = return empty
378+ paragraph (PageBreak : rest) | endsWithPageBreak rest = paraWithBreak PageBoth rest
379+ paragraph (PageBreak : rest) = paraWithBreak PageBefore rest
380+ paragraph inlines | endsWithPageBreak inlines = paraWithBreak PageAfter inlines
381+ paragraph inlines = inParagraphTags =<< inlinesToOpenDocument o inlines
382+
383+ paraWithBreak :: ParaBreak -> [Inline] -> State WriterState Doc
384+ paraWithBreak breakKind bs = do
385+ pn <- paraBreakStyle breakKind
386+ withParagraphStyle o ("P" ++ show pn) [Para bs]
387+
373colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
388colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
374colHeadsToOpenDocument o tn ns hs =
389colHeadsToOpenDocument o tn ns hs =
375 inTagsIndented "table:table-header-rows" . inTagsIndented "table:table-row" . vcat <$>
390 inTagsIndented "table:table-header-rows" . inTagsIndented "table:table-row" . vcat <$>
@@ -562,6 +577,13 @@ paraStyle attrs = do
562 addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) paraProps
577 addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) paraProps
563 return pn
578 return pn
564
579
580+paraBreakStyle :: ParaBreak -> State WriterState Int
581+paraBreakStyle PageBefore = paraStyle "Text_20_body" [("fo:break-before", "page")]
582+paraBreakStyle PageAfter = paraStyle "Text_20_body" [("fo:break-after", "page")]
583+paraBreakStyle PageBoth = paraStyle "Text_20_body" [("fo:break-before", "page"), ("fo:break-after", "page")]
584+paraBreakStyle AutoNone = paraStyle "Text_20_body" []
585+
586+
565paraListStyle :: Int -> State WriterState Int
587paraListStyle :: Int -> State WriterState Int
566paraListStyle l = paraStyle
588paraListStyle l = paraStyle
567 [("style:parent-style-name","Text_20_body")
589 [("style:parent-style-name","Text_20_body")