git.iko.soy/typeable/pandoc
on master help sign in
Adds support for pagebreaks (when it makes sense)

Update all writers to take into account page breaks. A straightforwad, far from complete, implementation of page breaks in selected writers. Readers will have to follow in the future as well.

commita6b469c02b3c21cfc1b5169ea3e75b7388f55691 authorHubert Plociniczak <hubert.plociniczak@gmail.com> dateFri 11 Nov 2016, 13:09 (10 years ago) parent30b3412
22 files changed+48−11
src/Text/Pandoc/Writers/AsciiDoc.hs+2−1 src/Text/Pandoc/Writers/CommonMark.hs+1 src/Text/Pandoc/Writers/ConTeXt.hs+1 src/Text/Pandoc/Writers/Custom.hs+2 src/Text/Pandoc/Writers/Docbook.hs+3 src/Text/Pandoc/Writers/Docx.hs+8−1 src/Text/Pandoc/Writers/DokuWiki.hs+3−1 src/Text/Pandoc/Writers/FB2.hs+2 src/Text/Pandoc/Writers/HTML.hs+1 src/Text/Pandoc/Writers/Haddock.hs+2−1 src/Text/Pandoc/Writers/ICML.hs+1 src/Text/Pandoc/Writers/LaTeX.hs+1 src/Text/Pandoc/Writers/Man.hs+2−1 src/Text/Pandoc/Writers/Markdown.hs+2−1 src/Text/Pandoc/Writers/MediaWiki.hs+3−1 src/Text/Pandoc/Writers/Org.hs+2−1 src/Text/Pandoc/Writers/RST.hs+1 src/Text/Pandoc/Writers/RTF.hs+2−1 src/Text/Pandoc/Writers/TEI.hs+1 src/Text/Pandoc/Writers/Texinfo.hs+2 src/Text/Pandoc/Writers/Textile.hs+3−1 src/Text/Pandoc/Writers/ZimWiki.hs+3−1
src/Text/Pandoc/Writers/AsciiDoc.hs+2−1
@@ -411,7 +411,8 @@ inlineToAsciiDoc _ (Math DisplayMath str) =
411411inlineToAsciiDoc _ (RawInline f s)
412412 | f == "asciidoc" = return $ text s
413413 | otherwise = return empty
414−inlineToAsciiDoc _ (LineBreak) = return $ " +" <> cr
414+inlineToAsciiDoc _ LineBreak = return $ " +" <> cr
415+inlineToAsciiDoc _ PageBreak = return empty
415416inlineToAsciiDoc _ Space = return space
416417inlineToAsciiDoc opts SoftBreak =
417418 case writerWrapText opts of
src/Text/Pandoc/Writers/CommonMark.hs+1
@@ -139,6 +139,7 @@ inlineToNodes :: Inline -> [Node] -> [Node]
139139inlineToNodes (Str s) = (node (TEXT (T.pack s)) [] :)
140140inlineToNodes Space = (node (TEXT (T.pack " ")) [] :)
141141inlineToNodes LineBreak = (node LINEBREAK [] :)
142+inlineToNodes PageBreak = id
142143inlineToNodes SoftBreak = (node SOFTBREAK [] :)
143144inlineToNodes (Emph xs) = (node EMPH (inlinesToNodes xs) :)
144145inlineToNodes (Strong xs) = (node STRONG (inlinesToNodes xs) :)
src/Text/Pandoc/Writers/ConTeXt.hs+1
@@ -346,6 +346,7 @@ inlineToConTeXt SoftBreak = do
346346 WrapAuto -> space
347347 WrapNone -> space
348348 WrapPreserve -> cr
349+inlineToConTeXt PageBreak = return empty
349350inlineToConTeXt Space = return space
350351-- Handle HTML-like internal document references to sections
351352inlineToConTeXt (Link _ txt (('#' : ref), _)) = do
src/Text/Pandoc/Writers/Custom.hs+2
@@ -310,6 +310,8 @@ inlineToCustom lua (RawInline format str) =
310310
311311inlineToCustom lua (LineBreak) = callfunc lua "LineBreak"
312312
313+inlineToCustom lua (PageBreak) = callfunc lua "PageBreak"
314+
313315inlineToCustom lua (Link attr txt (src,tit)) =
314316 callfunc lua "Link" txt src tit (attrToMap attr)
315317
src/Text/Pandoc/Writers/Docbook.hs+3
@@ -356,6 +356,9 @@ inlineToDocbook opts (Math t str)
356356inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
357357 | otherwise = empty
358358inlineToDocbook _ LineBreak = text "\n"
359+-- currently ignore, would require the option to add custom
360+-- styles to the document
361+inlineToDocbook _ PageBreak = empty
359362inlineToDocbook _ Space = space
360363-- because we use \n for LineBreak, we can't do soft breaks:
361364inlineToDocbook _ SoftBreak = space
src/Text/Pandoc/Writers/Docx.hs+8−1
@@ -1100,6 +1100,7 @@ inlineToOpenXML' opts (Strikeout lst) =
11001100 withTextProp (mknode "w:strike" [] ())
11011101 $ inlinesToOpenXML opts lst
11021102inlineToOpenXML' _ LineBreak = return [br]
1103+inlineToOpenXML' _ PageBreak = return [pageBreak]
11031104inlineToOpenXML' _ (RawInline f str)
11041105 | f == Format "openxml" = return [ x | Elem x <- parseXML str ]
11051106 | otherwise = return []
@@ -1247,7 +1248,13 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
12471248 return [imgElt]
12481249
12491250br :: Element
1250−br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
1251+br = breakElement "textWrapping"
1252+
1253+pageBreak :: Element
1254+pageBreak = breakElement "page"
1255+
1256+breakElement :: String -> Element
1257+breakElement kind = mknode "w:r" [] [mknode "w:br" [("w:type",kind)] () ]
12511258
12521259-- Word will insert these footnotes into the settings.xml file
12531260-- (whether or not they're visible in the document). If they're in the
src/Text/Pandoc/Writers/DokuWiki.hs+3−1
@@ -465,7 +465,9 @@ inlineToDokuWiki _ (RawInline f str)
465465 | f == Format "html" = return $ "<html>" ++ str ++ "</html>"
466466 | otherwise = return ""
467467
468−inlineToDokuWiki _ (LineBreak) = return "\\\\\n"
468+inlineToDokuWiki _ LineBreak = return "\\\\\n"
469+
470+inlineToDokuWiki _ PageBreak = return mempty
469471
470472inlineToDokuWiki opts SoftBreak =
471473 case writerWrapText opts of
src/Text/Pandoc/Writers/FB2.hs+2
@@ -443,6 +443,7 @@ toXml (Code _ s) = return [el "code" s]
443443toXml Space = return [txt " "]
444444toXml SoftBreak = return [txt " "]
445445toXml LineBreak = return [el "empty-line" ()]
446+toXml PageBreak = return []
446447toXml (Math _ formula) = insertMath InlineImage formula
447448toXml (RawInline _ _) = return [] -- raw TeX and raw HTML are suppressed
448449toXml (Link _ text (url,ttl)) = do
@@ -574,6 +575,7 @@ plain (Code _ s) = s
574575plain Space = " "
575576plain SoftBreak = " "
576577plain LineBreak = "\n"
578+plain PageBreak = "\n"
577579plain (Math _ s) = s
578580plain (RawInline _ s) = s
579581plain (Link _ text (url,_)) = concat (map plain text ++ [" <", url, ">"])
src/Text/Pandoc/Writers/HTML.hs+1
@@ -705,6 +705,7 @@ inlineToHtml opts inline =
705705 WrapPreserve -> preEscapedString "\n"
706706 (LineBreak) -> return $ (if writerHtml5 opts then H5.br else H.br)
707707 <> strToHtml "\n"
708+ (PageBreak) -> return mempty
708709 (Span (id',classes,kvs) ils)
709710 -> inlineListToHtml opts ils >>=
710711 return . addAttrs opts attr' . H.span
src/Text/Pandoc/Writers/Haddock.hs+2−1
@@ -326,7 +326,8 @@ inlineToHaddock _ (RawInline f str)
326326 | f == "haddock" = return $ text str
327327 | otherwise = return empty
328328-- no line break in haddock (see above on CodeBlock)
329−inlineToHaddock _ (LineBreak) = return cr
329+inlineToHaddock _ LineBreak = return cr
330+inlineToHaddock _ PageBreak = return empty
330331inlineToHaddock opts SoftBreak =
331332 case writerWrapText opts of
332333 WrapAuto -> return space
src/Text/Pandoc/Writers/ICML.hs+1
@@ -432,6 +432,7 @@ inlineToICML opts style SoftBreak =
432432 WrapNone -> charStyle style space
433433 WrapPreserve -> charStyle style cr
434434inlineToICML _ style LineBreak = charStyle style $ text lineSeparator
435+inlineToICML _ _ PageBreak = return empty
435436inlineToICML opts style (Math mt str) =
436437 cat <$> mapM (inlineToICML opts style) (texMathToInlines mt str)
437438inlineToICML _ _ (RawInline f str)
src/Text/Pandoc/Writers/LaTeX.hs+1
@@ -960,6 +960,7 @@ inlineToLaTeX SoftBreak = do
960960 WrapAuto -> return space
961961 WrapNone -> return space
962962 WrapPreserve -> return cr
963+inlineToLaTeX PageBreak = return $ "\\clearpage{}"
963964inlineToLaTeX Space = return space
964965inlineToLaTeX (Link _ txt ('#':ident, _)) = do
965966 contents <- inlineListToLaTeX txt
src/Text/Pandoc/Writers/Man.hs+2−1
@@ -342,8 +342,9 @@ inlineToMan opts (Math DisplayMath str) = do
342342inlineToMan _ (RawInline f str)
343343 | f == Format "man" = return $ text str
344344 | otherwise = return empty
345−inlineToMan _ (LineBreak) = return $
345+inlineToMan _ LineBreak = return $
346346 cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
347+inlineToMan _ PageBreak = return empty
347348inlineToMan _ SoftBreak = return space
348349inlineToMan _ Space = return space
349350inlineToMan opts (Link _ txt (src, _)) = do
src/Text/Pandoc/Writers/Markdown.hs+2−1
@@ -345,7 +345,7 @@ notesAndRefs opts = do
345345 if | writerReferenceLocation opts == EndOfDocument -> empty
346346 | isEmpty notes' && isEmpty refs' -> empty
347347 | otherwise -> blankline
348−
348+
349349 return $
350350 (if isEmpty notes' then empty else blankline <> notes') <>
351351 (if isEmpty refs' then empty else blankline <> refs') <>
@@ -1018,6 +1018,7 @@ inlineToMarkdown opts SoftBreak = do
10181018 WrapNone -> space'
10191019 WrapAuto -> space'
10201020 WrapPreserve -> cr
1021+inlineToMarkdown _ PageBreak = return empty
10211022inlineToMarkdown opts (Cite [] lst) = inlineListToMarkdown opts lst
10221023inlineToMarkdown opts (Cite (c:cs) lst)
10231024 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
src/Text/Pandoc/Writers/MediaWiki.hs+3−1
@@ -402,7 +402,9 @@ inlineToMediaWiki (RawInline f str)
402402 | f == Format "html" = return str
403403 | otherwise = return ""
404404
405−inlineToMediaWiki (LineBreak) = return "<br />\n"
405+inlineToMediaWiki LineBreak = return "<br />\n"
406+
407+inlineToMediaWiki PageBreak = return mempty
406408
407409inlineToMediaWiki SoftBreak = do
408410 wrapText <- gets (writerWrapText . stOptions)
src/Text/Pandoc/Writers/Org.hs+2−1
@@ -349,7 +349,8 @@ inlineToOrg (RawInline f@(Format f') str) =
349349 return $ if isRawFormat f
350350 then text str
351351 else "@@" <> text f' <> ":" <> text str <> "@@"
352−inlineToOrg (LineBreak) = return (text "\\\\" <> cr)
352+inlineToOrg LineBreak = return (text "\\\\" <> cr)
353+inlineToOrg PageBreak = return empty
353354inlineToOrg Space = return space
354355inlineToOrg SoftBreak = do
355356 wrapText <- gets (writerWrapText . stOptions)
src/Text/Pandoc/Writers/RST.hs+1
@@ -461,6 +461,7 @@ inlineToRST SoftBreak = do
461461 WrapPreserve -> return cr
462462 WrapAuto -> return space
463463 WrapNone -> return space
464+inlineToRST PageBreak = return $ ".. pagebreak::"
464465-- autolink
465466inlineToRST (Link _ [Str str] (src, _))
466467 | isURI src &&
src/Text/Pandoc/Writers/RTF.hs+2−1
@@ -350,8 +350,9 @@ inlineToRTF (Cite _ lst) = inlineListToRTF lst
350350inlineToRTF (RawInline f str)
351351 | f == Format "rtf" = str
352352 | otherwise = ""
353−inlineToRTF (LineBreak) = "\\line "
353+inlineToRTF LineBreak = "\\line "
354354inlineToRTF SoftBreak = " "
355+inlineToRTF PageBreak = "\\page "
355356inlineToRTF Space = " "
356357inlineToRTF (Link _ text (src, _)) =
357358 "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
src/Text/Pandoc/Writers/TEI.hs+1
@@ -284,6 +284,7 @@ inlineToTEI _ (Math t str) =
284284inlineToTEI _ (RawInline f x) | f == "tei" = text x
285285 | otherwise = empty
286286inlineToTEI _ LineBreak = selfClosingTag "lb" []
287+inlineToTEI _ PageBreak = selfClosingTag "pb" []
287288inlineToTEI _ Space = space
288289-- because we use \n for LineBreak, we can't do soft breaks:
289290inlineToTEI _ SoftBreak = space
src/Text/Pandoc/Writers/Texinfo.hs+2
@@ -437,6 +437,8 @@ inlineToTexinfo SoftBreak = do
437437 WrapPreserve -> return cr
438438inlineToTexinfo Space = return space
439439
440+inlineToTexinfo PageBreak = return $ text "@page"
441+
440442inlineToTexinfo (Link _ txt (src@('#':_), _)) = do
441443 contents <- escapeCommas $ inlineListToTexinfo txt
442444 return $ text "@ref" <>
src/Text/Pandoc/Writers/Textile.hs+3−1
@@ -435,7 +435,9 @@ inlineToTextile opts (RawInline f str)
435435 isEnabled Ext_raw_tex opts = return str
436436 | otherwise = return ""
437437
438−inlineToTextile _ (LineBreak) = return "\n"
438+inlineToTextile _ LineBreak = return "\n"
439+
440+inlineToTextile _ PageBreak = return mempty
439441
440442inlineToTextile _ SoftBreak = return " "
441443
src/Text/Pandoc/Writers/ZimWiki.hs+3−1
@@ -317,7 +317,9 @@ inlineToZimWiki opts (RawInline f str)
317317 | f == Format "html" = do cont <- indentFromHTML opts str; return cont
318318 | otherwise = return ""
319319
320−inlineToZimWiki _ (LineBreak) = return "\n" -- was \\\\
320+inlineToZimWiki _ LineBreak = return "\n" -- was \\\\
321+
322+inlineToZimWiki _ PageBreak = return mempty
321323
322324inlineToZimWiki opts SoftBreak =
323325 case writerWrapText opts of