git.iko.soy/typeable/pandoc
on master help sign in
Adds support for pagebreaks (when it makes sense)
a6b469cHubert Plociniczak
src/Text/Pandoc/Writers/AsciiDoc.hs+2−1
@@ -411,7 +411,8 @@ inlineToAsciiDoc _ (Math DisplayMath str) =
411inlineToAsciiDoc _ (RawInline f s)
411inlineToAsciiDoc _ (RawInline f s)
412 | f == "asciidoc" = return $ text s
412 | f == "asciidoc" = return $ text s
413 | otherwise = return empty
413 | otherwise = return empty
414−inlineToAsciiDoc _ (LineBreak) = return $ " +" <> cr
414+inlineToAsciiDoc _ LineBreak = return $ " +" <> cr
415+inlineToAsciiDoc _ PageBreak = return empty
415inlineToAsciiDoc _ Space = return space
416inlineToAsciiDoc _ Space = return space
416inlineToAsciiDoc opts SoftBreak =
417inlineToAsciiDoc opts SoftBreak =
417 case writerWrapText opts of
418 case writerWrapText opts of
src/Text/Pandoc/Writers/CommonMark.hs+1
@@ -139,6 +139,7 @@ inlineToNodes :: Inline -> [Node] -> [Node]
139inlineToNodes (Str s) = (node (TEXT (T.pack s)) [] :)
139inlineToNodes (Str s) = (node (TEXT (T.pack s)) [] :)
140inlineToNodes Space = (node (TEXT (T.pack " ")) [] :)
140inlineToNodes Space = (node (TEXT (T.pack " ")) [] :)
141inlineToNodes LineBreak = (node LINEBREAK [] :)
141inlineToNodes LineBreak = (node LINEBREAK [] :)
142+inlineToNodes PageBreak = id
142inlineToNodes SoftBreak = (node SOFTBREAK [] :)
143inlineToNodes SoftBreak = (node SOFTBREAK [] :)
143inlineToNodes (Emph xs) = (node EMPH (inlinesToNodes xs) :)
144inlineToNodes (Emph xs) = (node EMPH (inlinesToNodes xs) :)
144inlineToNodes (Strong xs) = (node STRONG (inlinesToNodes xs) :)
145inlineToNodes (Strong xs) = (node STRONG (inlinesToNodes xs) :)
src/Text/Pandoc/Writers/ConTeXt.hs+1
@@ -346,6 +346,7 @@ inlineToConTeXt SoftBreak = do
346 WrapAuto -> space
346 WrapAuto -> space
347 WrapNone -> space
347 WrapNone -> space
348 WrapPreserve -> cr
348 WrapPreserve -> cr
349+inlineToConTeXt PageBreak = return empty
349inlineToConTeXt Space = return space
350inlineToConTeXt Space = return space
350-- Handle HTML-like internal document references to sections
351-- Handle HTML-like internal document references to sections
351inlineToConTeXt (Link _ txt (('#' : ref), _)) = do
352inlineToConTeXt (Link _ txt (('#' : ref), _)) = do
src/Text/Pandoc/Writers/Custom.hs+2
@@ -310,6 +310,8 @@ inlineToCustom lua (RawInline format str) =
310
310
311inlineToCustom lua (LineBreak) = callfunc lua "LineBreak"
311inlineToCustom lua (LineBreak) = callfunc lua "LineBreak"
312
312
313+inlineToCustom lua (PageBreak) = callfunc lua "PageBreak"
314+
313inlineToCustom lua (Link attr txt (src,tit)) =
315inlineToCustom lua (Link attr txt (src,tit)) =
314 callfunc lua "Link" txt src tit (attrToMap attr)
316 callfunc lua "Link" txt src tit (attrToMap attr)
315
317
src/Text/Pandoc/Writers/Docbook.hs+3
@@ -356,6 +356,9 @@ inlineToDocbook opts (Math t str)
356inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
356inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
357 | otherwise = empty
357 | otherwise = empty
358inlineToDocbook _ LineBreak = text "\n"
358inlineToDocbook _ LineBreak = text "\n"
359+-- currently ignore, would require the option to add custom
360+-- styles to the document
361+inlineToDocbook _ PageBreak = empty
359inlineToDocbook _ Space = space
362inlineToDocbook _ Space = space
360-- because we use \n for LineBreak, we can't do soft breaks:
363-- because we use \n for LineBreak, we can't do soft breaks:
361inlineToDocbook _ SoftBreak = space
364inlineToDocbook _ SoftBreak = space
src/Text/Pandoc/Writers/Docx.hs+8−1
@@ -1100,6 +1100,7 @@ inlineToOpenXML' opts (Strikeout lst) =
1100 withTextProp (mknode "w:strike" [] ())
1100 withTextProp (mknode "w:strike" [] ())
1101 $ inlinesToOpenXML opts lst
1101 $ inlinesToOpenXML opts lst
1102inlineToOpenXML' _ LineBreak = return [br]
1102inlineToOpenXML' _ LineBreak = return [br]
1103+inlineToOpenXML' _ PageBreak = return [pageBreak]
1103inlineToOpenXML' _ (RawInline f str)
1104inlineToOpenXML' _ (RawInline f str)
1104 | f == Format "openxml" = return [ x | Elem x <- parseXML str ]
1105 | f == Format "openxml" = return [ x | Elem x <- parseXML str ]
1105 | otherwise = return []
1106 | otherwise = return []
@@ -1247,7 +1248,13 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1247 return [imgElt]
1248 return [imgElt]
1248
1249
1249br :: Element
1250br :: Element
1251+br = breakElement "textWrapping"
1252+
1253+pageBreak :: Element
1254+pageBreak = breakElement "page"
1255+
1256+breakElement :: String -> Element
1250−br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
1257+breakElement kind = mknode "w:r" [] [mknode "w:br" [("w:type",kind)] () ]
1251
1258
1252-- Word will insert these footnotes into the settings.xml file
1259-- Word will insert these footnotes into the settings.xml file
1253-- (whether or not they're visible in the document). If they're in the
1260-- (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)
465 | f == Format "html" = return $ "<html>" ++ str ++ "</html>"
465 | f == Format "html" = return $ "<html>" ++ str ++ "</html>"
466 | otherwise = return ""
466 | otherwise = return ""
467
467
468−inlineToDokuWiki _ (LineBreak) = return "\\\\\n"
468+inlineToDokuWiki _ LineBreak = return "\\\\\n"
469+
470+inlineToDokuWiki _ PageBreak = return mempty
469
471
470inlineToDokuWiki opts SoftBreak =
472inlineToDokuWiki opts SoftBreak =
471 case writerWrapText opts of
473 case writerWrapText opts of
src/Text/Pandoc/Writers/FB2.hs+2
@@ -443,6 +443,7 @@ toXml (Code _ s) = return [el "code" s]
443toXml Space = return [txt " "]
443toXml Space = return [txt " "]
444toXml SoftBreak = return [txt " "]
444toXml SoftBreak = return [txt " "]
445toXml LineBreak = return [el "empty-line" ()]
445toXml LineBreak = return [el "empty-line" ()]
446+toXml PageBreak = return []
446toXml (Math _ formula) = insertMath InlineImage formula
447toXml (Math _ formula) = insertMath InlineImage formula
447toXml (RawInline _ _) = return [] -- raw TeX and raw HTML are suppressed
448toXml (RawInline _ _) = return [] -- raw TeX and raw HTML are suppressed
448toXml (Link _ text (url,ttl)) = do
449toXml (Link _ text (url,ttl)) = do
@@ -574,6 +575,7 @@ plain (Code _ s) = s
574plain Space = " "
575plain Space = " "
575plain SoftBreak = " "
576plain SoftBreak = " "
576plain LineBreak = "\n"
577plain LineBreak = "\n"
578+plain PageBreak = "\n"
577plain (Math _ s) = s
579plain (Math _ s) = s
578plain (RawInline _ s) = s
580plain (RawInline _ s) = s
579plain (Link _ text (url,_)) = concat (map plain text ++ [" <", url, ">"])
581plain (Link _ text (url,_)) = concat (map plain text ++ [" <", url, ">"])
src/Text/Pandoc/Writers/HTML.hs+1
@@ -705,6 +705,7 @@ inlineToHtml opts inline =
705 WrapPreserve -> preEscapedString "\n"
705 WrapPreserve -> preEscapedString "\n"
706 (LineBreak) -> return $ (if writerHtml5 opts then H5.br else H.br)
706 (LineBreak) -> return $ (if writerHtml5 opts then H5.br else H.br)
707 <> strToHtml "\n"
707 <> strToHtml "\n"
708+ (PageBreak) -> return mempty
708 (Span (id',classes,kvs) ils)
709 (Span (id',classes,kvs) ils)
709 -> inlineListToHtml opts ils >>=
710 -> inlineListToHtml opts ils >>=
710 return . addAttrs opts attr' . H.span
711 return . addAttrs opts attr' . H.span
src/Text/Pandoc/Writers/Haddock.hs+2−1
@@ -326,7 +326,8 @@ inlineToHaddock _ (RawInline f str)
326 | f == "haddock" = return $ text str
326 | f == "haddock" = return $ text str
327 | otherwise = return empty
327 | otherwise = return empty
328-- no line break in haddock (see above on CodeBlock)
328-- no line break in haddock (see above on CodeBlock)
329−inlineToHaddock _ (LineBreak) = return cr
329+inlineToHaddock _ LineBreak = return cr
330+inlineToHaddock _ PageBreak = return empty
330inlineToHaddock opts SoftBreak =
331inlineToHaddock opts SoftBreak =
331 case writerWrapText opts of
332 case writerWrapText opts of
332 WrapAuto -> return space
333 WrapAuto -> return space
src/Text/Pandoc/Writers/ICML.hs+1
@@ -432,6 +432,7 @@ inlineToICML opts style SoftBreak =
432 WrapNone -> charStyle style space
432 WrapNone -> charStyle style space
433 WrapPreserve -> charStyle style cr
433 WrapPreserve -> charStyle style cr
434inlineToICML _ style LineBreak = charStyle style $ text lineSeparator
434inlineToICML _ style LineBreak = charStyle style $ text lineSeparator
435+inlineToICML _ _ PageBreak = return empty
435inlineToICML opts style (Math mt str) =
436inlineToICML opts style (Math mt str) =
436 cat <$> mapM (inlineToICML opts style) (texMathToInlines mt str)
437 cat <$> mapM (inlineToICML opts style) (texMathToInlines mt str)
437inlineToICML _ _ (RawInline f str)
438inlineToICML _ _ (RawInline f str)
src/Text/Pandoc/Writers/LaTeX.hs+1
@@ -960,6 +960,7 @@ inlineToLaTeX SoftBreak = do
960 WrapAuto -> return space
960 WrapAuto -> return space
961 WrapNone -> return space
961 WrapNone -> return space
962 WrapPreserve -> return cr
962 WrapPreserve -> return cr
963+inlineToLaTeX PageBreak = return $ "\\clearpage{}"
963inlineToLaTeX Space = return space
964inlineToLaTeX Space = return space
964inlineToLaTeX (Link _ txt ('#':ident, _)) = do
965inlineToLaTeX (Link _ txt ('#':ident, _)) = do
965 contents <- inlineListToLaTeX txt
966 contents <- inlineListToLaTeX txt
src/Text/Pandoc/Writers/Man.hs+2−1
@@ -342,8 +342,9 @@ inlineToMan opts (Math DisplayMath str) = do
342inlineToMan _ (RawInline f str)
342inlineToMan _ (RawInline f str)
343 | f == Format "man" = return $ text str
343 | f == Format "man" = return $ text str
344 | otherwise = return empty
344 | otherwise = return empty
345−inlineToMan _ (LineBreak) = return $
345+inlineToMan _ LineBreak = return $
346 cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
346 cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
347+inlineToMan _ PageBreak = return empty
347inlineToMan _ SoftBreak = return space
348inlineToMan _ SoftBreak = return space
348inlineToMan _ Space = return space
349inlineToMan _ Space = return space
349inlineToMan opts (Link _ txt (src, _)) = do
350inlineToMan opts (Link _ txt (src, _)) = do
src/Text/Pandoc/Writers/Markdown.hs+2−1
@@ -345,7 +345,7 @@ notesAndRefs opts = do
345 if | writerReferenceLocation opts == EndOfDocument -> empty
345 if | writerReferenceLocation opts == EndOfDocument -> empty
346 | isEmpty notes' && isEmpty refs' -> empty
346 | isEmpty notes' && isEmpty refs' -> empty
347 | otherwise -> blankline
347 | otherwise -> blankline
348−
348+
349 return $
349 return $
350 (if isEmpty notes' then empty else blankline <> notes') <>
350 (if isEmpty notes' then empty else blankline <> notes') <>
351 (if isEmpty refs' then empty else blankline <> refs') <>
351 (if isEmpty refs' then empty else blankline <> refs') <>
@@ -1018,6 +1018,7 @@ inlineToMarkdown opts SoftBreak = do
1018 WrapNone -> space'
1018 WrapNone -> space'
1019 WrapAuto -> space'
1019 WrapAuto -> space'
1020 WrapPreserve -> cr
1020 WrapPreserve -> cr
1021+inlineToMarkdown _ PageBreak = return empty
1021inlineToMarkdown opts (Cite [] lst) = inlineListToMarkdown opts lst
1022inlineToMarkdown opts (Cite [] lst) = inlineListToMarkdown opts lst
1022inlineToMarkdown opts (Cite (c:cs) lst)
1023inlineToMarkdown opts (Cite (c:cs) lst)
1023 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
1024 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
src/Text/Pandoc/Writers/MediaWiki.hs+3−1
@@ -402,7 +402,9 @@ inlineToMediaWiki (RawInline f str)
402 | f == Format "html" = return str
402 | f == Format "html" = return str
403 | otherwise = return ""
403 | otherwise = return ""
404
404
405−inlineToMediaWiki (LineBreak) = return "<br />\n"
405+inlineToMediaWiki LineBreak = return "<br />\n"
406+
407+inlineToMediaWiki PageBreak = return mempty
406
408
407inlineToMediaWiki SoftBreak = do
409inlineToMediaWiki SoftBreak = do
408 wrapText <- gets (writerWrapText . stOptions)
410 wrapText <- gets (writerWrapText . stOptions)
src/Text/Pandoc/Writers/Org.hs+2−1
@@ -349,7 +349,8 @@ inlineToOrg (RawInline f@(Format f') str) =
349 return $ if isRawFormat f
349 return $ if isRawFormat f
350 then text str
350 then text str
351 else "@@" <> text f' <> ":" <> text str <> "@@"
351 else "@@" <> text f' <> ":" <> text str <> "@@"
352−inlineToOrg (LineBreak) = return (text "\\\\" <> cr)
352+inlineToOrg LineBreak = return (text "\\\\" <> cr)
353+inlineToOrg PageBreak = return empty
353inlineToOrg Space = return space
354inlineToOrg Space = return space
354inlineToOrg SoftBreak = do
355inlineToOrg SoftBreak = do
355 wrapText <- gets (writerWrapText . stOptions)
356 wrapText <- gets (writerWrapText . stOptions)
src/Text/Pandoc/Writers/RST.hs+1
@@ -461,6 +461,7 @@ inlineToRST SoftBreak = do
461 WrapPreserve -> return cr
461 WrapPreserve -> return cr
462 WrapAuto -> return space
462 WrapAuto -> return space
463 WrapNone -> return space
463 WrapNone -> return space
464+inlineToRST PageBreak = return $ ".. pagebreak::"
464-- autolink
465-- autolink
465inlineToRST (Link _ [Str str] (src, _))
466inlineToRST (Link _ [Str str] (src, _))
466 | isURI src &&
467 | isURI src &&
src/Text/Pandoc/Writers/RTF.hs+2−1
@@ -350,8 +350,9 @@ inlineToRTF (Cite _ lst) = inlineListToRTF lst
350inlineToRTF (RawInline f str)
350inlineToRTF (RawInline f str)
351 | f == Format "rtf" = str
351 | f == Format "rtf" = str
352 | otherwise = ""
352 | otherwise = ""
353−inlineToRTF (LineBreak) = "\\line "
353+inlineToRTF LineBreak = "\\line "
354inlineToRTF SoftBreak = " "
354inlineToRTF SoftBreak = " "
355+inlineToRTF PageBreak = "\\page "
355inlineToRTF Space = " "
356inlineToRTF Space = " "
356inlineToRTF (Link _ text (src, _)) =
357inlineToRTF (Link _ text (src, _)) =
357 "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
358 "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
src/Text/Pandoc/Writers/TEI.hs+1
@@ -284,6 +284,7 @@ inlineToTEI _ (Math t str) =
284inlineToTEI _ (RawInline f x) | f == "tei" = text x
284inlineToTEI _ (RawInline f x) | f == "tei" = text x
285 | otherwise = empty
285 | otherwise = empty
286inlineToTEI _ LineBreak = selfClosingTag "lb" []
286inlineToTEI _ LineBreak = selfClosingTag "lb" []
287+inlineToTEI _ PageBreak = selfClosingTag "pb" []
287inlineToTEI _ Space = space
288inlineToTEI _ Space = space
288-- because we use \n for LineBreak, we can't do soft breaks:
289-- because we use \n for LineBreak, we can't do soft breaks:
289inlineToTEI _ SoftBreak = space
290inlineToTEI _ SoftBreak = space
src/Text/Pandoc/Writers/Texinfo.hs+2
@@ -437,6 +437,8 @@ inlineToTexinfo SoftBreak = do
437 WrapPreserve -> return cr
437 WrapPreserve -> return cr
438inlineToTexinfo Space = return space
438inlineToTexinfo Space = return space
439
439
440+inlineToTexinfo PageBreak = return $ text "@page"
441+
440inlineToTexinfo (Link _ txt (src@('#':_), _)) = do
442inlineToTexinfo (Link _ txt (src@('#':_), _)) = do
441 contents <- escapeCommas $ inlineListToTexinfo txt
443 contents <- escapeCommas $ inlineListToTexinfo txt
442 return $ text "@ref" <>
444 return $ text "@ref" <>
src/Text/Pandoc/Writers/Textile.hs+3−1
@@ -435,7 +435,9 @@ inlineToTextile opts (RawInline f str)
435 isEnabled Ext_raw_tex opts = return str
435 isEnabled Ext_raw_tex opts = return str
436 | otherwise = return ""
436 | otherwise = return ""
437
437
438−inlineToTextile _ (LineBreak) = return "\n"
438+inlineToTextile _ LineBreak = return "\n"
439+
440+inlineToTextile _ PageBreak = return mempty
439
441
440inlineToTextile _ SoftBreak = return " "
442inlineToTextile _ SoftBreak = return " "
441
443
src/Text/Pandoc/Writers/ZimWiki.hs+3−1
@@ -317,7 +317,9 @@ inlineToZimWiki opts (RawInline f str)
317 | f == Format "html" = do cont <- indentFromHTML opts str; return cont
317 | f == Format "html" = do cont <- indentFromHTML opts str; return cont
318 | otherwise = return ""
318 | otherwise = return ""
319
319
320−inlineToZimWiki _ (LineBreak) = return "\n" -- was \\\\
320+inlineToZimWiki _ LineBreak = return "\n" -- was \\\\
321+
322+inlineToZimWiki _ PageBreak = return mempty
321
323
322inlineToZimWiki opts SoftBreak =
324inlineToZimWiki opts SoftBreak =
323 case writerWrapText opts of
325 case writerWrapText opts of