git.iko.soy/typeable/pandoc
on master help sign in
Add support for the LineBlock element to writers
22cb9e3Albert Krewinkel
src/Text/Pandoc/Writers/AsciiDoc.hs+7−1
@@ -137,6 +137,13 @@ blockToAsciiDoc opts (Para inlines) = do
137 then text "\\"
137 then text "\\"
138 else empty
138 else empty
139 return $ esc <> contents <> blankline
139 return $ esc <> contents <> blankline
140+blockToAsciiDoc opts (LineBlock lns) = do
141+ let docify line = if null line
142+ then return blankline
143+ else inlineListToAsciiDoc opts line
144+ let joinWithLinefeeds = nowrap . mconcat . intersperse cr
145+ contents <- joinWithLinefeeds <$> mapM docify lns
146+ return $ "[verse]" $$ text "--" $$ contents $$ text "--" $$ blankline
140blockToAsciiDoc _ (RawBlock f s)
147blockToAsciiDoc _ (RawBlock f s)
141 | f == "asciidoc" = return $ text s
148 | f == "asciidoc" = return $ text s
142 | otherwise = return empty
149 | otherwise = return empty
@@ -459,4 +466,3 @@ inlineToAsciiDoc opts (Span (ident,_,_) ils) = do
459 let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
466 let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
460 contents <- inlineListToAsciiDoc opts ils
467 contents <- inlineListToAsciiDoc opts ils
461 return $ identifier <> contents
468 return $ identifier <> contents
462−
src/Text/Pandoc/Writers/CommonMark.hs+2−1
@@ -33,7 +33,7 @@ module Text.Pandoc.Writers.CommonMark (writeCommonMark) where
33
33
34import Text.Pandoc.Writers.HTML (writeHtmlString)
34import Text.Pandoc.Writers.HTML (writeHtmlString)
35import Text.Pandoc.Definition
35import Text.Pandoc.Definition
36−import Text.Pandoc.Shared (isTightList)
36+import Text.Pandoc.Shared (isTightList, linesToPara)
37import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Templates (renderTemplate')
38import Text.Pandoc.Writers.Shared
38import Text.Pandoc.Writers.Shared
39import Text.Pandoc.Options
39import Text.Pandoc.Options
@@ -94,6 +94,7 @@ blocksToNodes = foldr blockToNodes []
94blockToNodes :: Block -> [Node] -> [Node]
94blockToNodes :: Block -> [Node] -> [Node]
95blockToNodes (Plain xs) = (node PARAGRAPH (inlinesToNodes xs) :)
95blockToNodes (Plain xs) = (node PARAGRAPH (inlinesToNodes xs) :)
96blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
96blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
97+blockToNodes (LineBlock lns) = blockToNodes $ linesToPara lns
97blockToNodes (CodeBlock (_,classes,_) xs) =
98blockToNodes (CodeBlock (_,classes,_) xs) =
98 (node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
99 (node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
99blockToNodes (RawBlock fmt xs)
100blockToNodes (RawBlock fmt xs)
src/Text/Pandoc/Writers/ConTeXt.hs+3−1
@@ -163,6 +163,9 @@ blockToConTeXt (Para [Image attr txt (src,'f':'i':'g':':':_)]) = do
163blockToConTeXt (Para lst) = do
163blockToConTeXt (Para lst) = do
164 contents <- inlineListToConTeXt lst
164 contents <- inlineListToConTeXt lst
165 return $ contents <> blankline
165 return $ contents <> blankline
166+blockToConTeXt (LineBlock lns) = do
167+ doclines <- nowrap . vcat <$> mapM inlineListToConTeXt lns
168+ return $ "\\startlines" $$ doclines $$ "\\stoplines" <> blankline
166blockToConTeXt (BlockQuote lst) = do
169blockToConTeXt (BlockQuote lst) = do
167 contents <- blockListToConTeXt lst
170 contents <- blockListToConTeXt lst
168 return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
171 return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
@@ -467,4 +470,3 @@ fromBcp47 x = fromIso $ head x
467 fromIso "vi" = "vn"
470 fromIso "vi" = "vn"
468 fromIso "zh" = "cn"
471 fromIso "zh" = "cn"
469 fromIso l = l
472 fromIso l = l
470−
src/Text/Pandoc/Writers/Custom.hs+2
@@ -227,6 +227,8 @@ blockToCustom lua (Para [Image attr txt (src,tit)]) =
227
227
228blockToCustom lua (Para inlines) = callfunc lua "Para" inlines
228blockToCustom lua (Para inlines) = callfunc lua "Para" inlines
229
229
230+blockToCustom lua (LineBlock linesList) = callfunc lua "LineBlock" linesList
231+
230blockToCustom lua (RawBlock format str) =
232blockToCustom lua (RawBlock format str) =
231 callfunc lua "RawBlock" format str
233 callfunc lua "RawBlock" format str
232
234
src/Text/Pandoc/Writers/Docbook.hs+2−1
@@ -198,6 +198,8 @@ blockToDocbook opts (Para [Image attr txt (src,'f':'i':'g':':':_)]) =
198blockToDocbook opts (Para lst)
198blockToDocbook opts (Para lst)
199 | hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
199 | hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
200 | otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
200 | otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
201+blockToDocbook opts (LineBlock lns) =
202+ blockToDocbook opts $ linesToPara lns
201blockToDocbook opts (BlockQuote blocks) =
203blockToDocbook opts (BlockQuote blocks) =
202 inTagsIndented "blockquote" $ blocksToDocbook opts blocks
204 inTagsIndented "blockquote" $ blocksToDocbook opts blocks
203blockToDocbook _ (CodeBlock (_,classes,_) str) =
205blockToDocbook _ (CodeBlock (_,classes,_) str) =
@@ -385,4 +387,3 @@ idAndRole (id',cls,_) = ident ++ role
385 role = if null cls
387 role = if null cls
386 then []
388 then []
387 else [("role", unwords cls)]
389 else [("role", unwords cls)]
388−
src/Text/Pandoc/Writers/Docx.hs+5−6
@@ -275,7 +275,7 @@ writeDocx opts doc@(Pandoc meta _) = do
275 }
275 }
276
276
277
277
278− ((contents, footnotes), st) <- runStateT
278+ ((contents, footnotes), st) <- runStateT
279 (runReaderT
279 (runReaderT
280 (writeOpenXML opts{writerWrapText = WrapNone} doc')
280 (writeOpenXML opts{writerWrapText = WrapNone} doc')
281 env)
281 env)
@@ -446,7 +446,7 @@ writeDocx opts doc@(Pandoc meta _) = do
446
446
447 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
447 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
448 map newTextPropToOpenXml newDynamicTextProps ++
448 map newTextPropToOpenXml newDynamicTextProps ++
449− (styleToOpenXml styleMaps $ writerHighlightStyle opts)
449+ (styleToOpenXml styleMaps $ writerHighlightStyle opts)
450 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
450 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
451 where
451 where
452 modifyContent
452 modifyContent
@@ -859,6 +859,7 @@ blockToOpenXML' opts (Para lst) = do
859 modify $ \s -> s { stFirstPara = False }
859 modify $ \s -> s { stFirstPara = False }
860 contents <- inlinesToOpenXML opts lst
860 contents <- inlinesToOpenXML opts lst
861 return [mknode "w:p" [] (paraProps' ++ contents)]
861 return [mknode "w:p" [] (paraProps' ++ contents)]
862+blockToOpenXML' opts (LineBlock lns) = blockToOpenXML opts $ linesToPara lns
862blockToOpenXML' _ (RawBlock format str)
863blockToOpenXML' _ (RawBlock format str)
863 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
864 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
864 | otherwise = return []
865 | otherwise = return []
@@ -1032,7 +1033,7 @@ setFirstPara = modify $ \s -> s { stFirstPara = True }
1032
1033
1033-- | Convert an inline element to OpenXML.
1034-- | Convert an inline element to OpenXML.
1034inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
1035inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
1035−inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
1036+inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
1036
1037
1037inlineToOpenXML' :: WriterOptions -> Inline -> WS [Element]
1038inlineToOpenXML' :: WriterOptions -> Inline -> WS [Element]
1038inlineToOpenXML' _ (Str str) = formattedString str
1039inlineToOpenXML' _ (Str str) = formattedString str
@@ -1286,7 +1287,7 @@ withDirection x = do
1286 textProps <- asks envTextProperties
1287 textProps <- asks envTextProperties
1287 -- We want to clean all bidirection (bidi) and right-to-left (rtl)
1288 -- We want to clean all bidirection (bidi) and right-to-left (rtl)
1288 -- properties from the props first. This is because we don't want
1289 -- properties from the props first. This is because we don't want
1289− -- them to stack up.
1290+ -- them to stack up.
1290 let paraProps' = filter (\e -> (qName . elName) e /= "bidi") paraProps
1291 let paraProps' = filter (\e -> (qName . elName) e /= "bidi") paraProps
1291 textProps' = filter (\e -> (qName . elName) e /= "rtl") textProps
1292 textProps' = filter (\e -> (qName . elName) e /= "rtl") textProps
1292 if isRTL
1293 if isRTL
@@ -1298,5 +1299,3 @@ withDirection x = do
1298 else flip local x $ \env -> env { envParaProperties = paraProps'
1299 else flip local x $ \env -> env { envParaProperties = paraProps'
1299 , envTextProperties = textProps'
1300 , envTextProperties = textProps'
1300 }
1301 }
1301−
1302−
src/Text/Pandoc/Writers/DokuWiki.hs+5−2
@@ -45,8 +45,8 @@ import Text.Pandoc.Options ( WriterOptions(
45 , writerStandalone
45 , writerStandalone
46 , writerTemplate
46 , writerTemplate
47 , writerWrapText), WrapOption(..) )
47 , writerWrapText), WrapOption(..) )
48−import Text.Pandoc.Shared ( escapeURI, removeFormatting, camelCaseToHyphenated
48+import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
49− , trimr, normalize, substitute )
49+ , camelCaseToHyphenated, trimr, normalize, substitute )
50import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
50import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
51import Text.Pandoc.ImageSize
51import Text.Pandoc.ImageSize
52import Text.Pandoc.Templates ( renderTemplate' )
52import Text.Pandoc.Templates ( renderTemplate' )
@@ -147,6 +147,9 @@ blockToDokuWiki opts (Para inlines) = do
147 then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
147 then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
148 else contents ++ if null indent then "\n" else ""
148 else contents ++ if null indent then "\n" else ""
149
149
150+blockToDokuWiki opts (LineBlock lns) =
151+ blockToDokuWiki opts $ linesToPara lns
152+
150blockToDokuWiki _ (RawBlock f str)
153blockToDokuWiki _ (RawBlock f str)
151 | f == Format "dokuwiki" = return str
154 | f == Format "dokuwiki" = return str
152 -- See https://www.dokuwiki.org/wiki:syntax
155 -- See https://www.dokuwiki.org/wiki:syntax
src/Text/Pandoc/Writers/FB2.hs+3−1
@@ -46,7 +46,8 @@ import qualified Text.XML.Light.Cursor as XC
46
46
47import Text.Pandoc.Definition
47import Text.Pandoc.Definition
48import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
48import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
49−import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize)
49+import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
50+ linesToPara)
50
51
51-- | Data to be written at the end of the document:
52-- | Data to be written at the end of the document:
52-- (foot)notes, URLs, references, images.
53-- (foot)notes, URLs, references, images.
@@ -323,6 +324,7 @@ blockToXml (RawBlock _ s) = return . spaceBeforeAfter .
323 map (el "p" . el "code") . lines $ s
324 map (el "p" . el "code") . lines $ s
324blockToXml (Div _ bs) = cMapM blockToXml bs
325blockToXml (Div _ bs) = cMapM blockToXml bs
325blockToXml (BlockQuote bs) = liftM (list . el "cite") $ cMapM blockToXml bs
326blockToXml (BlockQuote bs) = liftM (list . el "cite") $ cMapM blockToXml bs
327+blockToXml (LineBlock lns) = blockToXml $ linesToPara lns
326blockToXml (OrderedList a bss) = do
328blockToXml (OrderedList a bss) = do
327 state <- get
329 state <- get
328 let pmrk = parentListMarker state
330 let pmrk = parentListMarker state
src/Text/Pandoc/Writers/HTML.hs+8−1
@@ -463,6 +463,13 @@ blockToHtml opts (Para [Image attr txt (s,'f':'i':'g':':':tit)]) = do
463blockToHtml opts (Para lst) = do
463blockToHtml opts (Para lst) = do
464 contents <- inlineListToHtml opts lst
464 contents <- inlineListToHtml opts lst
465 return $ H.p contents
465 return $ H.p contents
466+blockToHtml opts (LineBlock lns) =
467+ if writerWrapText opts == WrapNone
468+ then blockToHtml opts $ linesToPara lns
469+ else do
470+ let lf = preEscapedString "\n"
471+ htmlLines <- mconcat . intersperse lf <$> mapM (inlineListToHtml opts) lns
472+ return $ H.div ! A.style "white-space: pre-line;" $ htmlLines
466blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
473blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
467 let speakerNotes = "notes" `elem` classes
474 let speakerNotes = "notes" `elem` classes
468 -- we don't want incremental output inside speaker notes, see #1394
475 -- we don't want incremental output inside speaker notes, see #1394
@@ -807,7 +814,7 @@ inlineToHtml opts inline =
807 let brtag = if writerHtml5 opts then H5.br else H.br
814 let brtag = if writerHtml5 opts then H5.br else H.br
808 return $ case t of
815 return $ case t of
809 InlineMath -> m
816 InlineMath -> m
810− DisplayMath -> brtag >> m >> brtag
817+ DisplayMath -> brtag >> m >> brtag
811 (RawInline f str)
818 (RawInline f str)
812 | f == Format "html" -> return $ preEscapedString str
819 | f == Format "html" -> return $ preEscapedString str
813 | otherwise -> return mempty
820 | otherwise -> return mempty
src/Text/Pandoc/Writers/Haddock.hs+2
@@ -108,6 +108,8 @@ blockToHaddock opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
108blockToHaddock opts (Para inlines) =
108blockToHaddock opts (Para inlines) =
109 -- TODO: if it contains linebreaks, we need to use a @...@ block
109 -- TODO: if it contains linebreaks, we need to use a @...@ block
110 (<> blankline) `fmap` blockToHaddock opts (Plain inlines)
110 (<> blankline) `fmap` blockToHaddock opts (Plain inlines)
111+blockToHaddock opts (LineBlock lns) =
112+ blockToHaddock opts $ linesToPara lns
111blockToHaddock _ (RawBlock f str)
113blockToHaddock _ (RawBlock f str)
112 | f == "haddock" = do
114 | f == "haddock" = do
113 return $ text str <> text "\n"
115 return $ text str <> text "\n"
src/Text/Pandoc/Writers/ICML.hs+4−2
@@ -2,7 +2,7 @@
2
2
3{- |
3{- |
4 Module : Text.Pandoc.Writers.ICML
4 Module : Text.Pandoc.Writers.ICML
5− Copyright : Copyright (C) 2013 github.com/mb21
5+ Copyright : Copyright (C) 2013-2016 github.com/mb21
6 License : GNU GPL, version 2 or above
6 License : GNU GPL, version 2 or above
7
7
8 Stability : alpha
8 Stability : alpha
@@ -18,7 +18,7 @@ import Text.Pandoc.Definition
18import Text.Pandoc.XML
18import Text.Pandoc.XML
19import Text.Pandoc.Readers.TeXMath (texMathToInlines)
19import Text.Pandoc.Readers.TeXMath (texMathToInlines)
20import Text.Pandoc.Writers.Shared
20import Text.Pandoc.Writers.Shared
21−import Text.Pandoc.Shared (splitBy, fetchItem, warn)
21+import Text.Pandoc.Shared (linesToPara, splitBy, fetchItem, warn)
22import Text.Pandoc.Options
22import Text.Pandoc.Options
23import Text.Pandoc.Templates (renderTemplate')
23import Text.Pandoc.Templates (renderTemplate')
24import Text.Pandoc.Pretty
24import Text.Pandoc.Pretty
@@ -297,6 +297,8 @@ blockToICML opts style (Para img@[Image _ txt (_,'f':'i':'g':':':_)]) = do
297 caption <- parStyle opts (imgCaptionName:style) txt
297 caption <- parStyle opts (imgCaptionName:style) txt
298 return $ intersperseBrs [figure, caption]
298 return $ intersperseBrs [figure, caption]
299blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
299blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
300+blockToICML opts style (LineBlock lns) =
301+ blockToICML opts style $ linesToPara lns
300blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
302blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
301blockToICML _ _ (RawBlock f str)
303blockToICML _ _ (RawBlock f str)
302 | f == Format "icml" = return $ text str
304 | f == Format "icml" = return $ text str
src/Text/Pandoc/Writers/LaTeX.hs+2
@@ -437,6 +437,8 @@ blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
437 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
437 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
438blockToLaTeX (Para lst) =
438blockToLaTeX (Para lst) =
439 inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
439 inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
440+blockToLaTeX (LineBlock lns) = do
441+ blockToLaTeX $ linesToPara lns
440blockToLaTeX (BlockQuote lst) = do
442blockToLaTeX (BlockQuote lst) = do
441 beamer <- writerBeamer `fmap` gets stOptions
443 beamer <- writerBeamer `fmap` gets stOptions
442 case lst of
444 case lst of
src/Text/Pandoc/Writers/Man.hs+2−1
@@ -171,6 +171,8 @@ blockToMan opts (Para inlines) = do
171 contents <- liftM vcat $ mapM (inlineListToMan opts) $
171 contents <- liftM vcat $ mapM (inlineListToMan opts) $
172 splitSentences inlines
172 splitSentences inlines
173 return $ text ".PP" $$ contents
173 return $ text ".PP" $$ contents
174+blockToMan opts (LineBlock lns) =
175+ blockToMan opts $ linesToPara lns
174blockToMan _ (RawBlock f str)
176blockToMan _ (RawBlock f str)
175 | f == Format "man" = return $ text str
177 | f == Format "man" = return $ text str
176 | otherwise = return empty
178 | otherwise = return empty
@@ -367,4 +369,3 @@ inlineToMan _ (Note contents) = do
367 notes <- liftM stNotes get
369 notes <- liftM stNotes get
368 let ref = show $ (length notes)
370 let ref = show $ (length notes)
369 return $ char '[' <> text ref <> char ']'
371 return $ char '[' <> text ref <> char ']'
370−
src/Text/Pandoc/Writers/Markdown.hs+7−1
@@ -79,7 +79,7 @@ instance Default WriterEnv
79 , envRefShortcutable = True
79 , envRefShortcutable = True
80 , envBlockLevel = 0
80 , envBlockLevel = 0
81 }
81 }
82−
82+
83data WriterState = WriterState { stNotes :: Notes
83data WriterState = WriterState { stNotes :: Notes
84 , stRefs :: Refs
84 , stRefs :: Refs
85 , stIds :: Set.Set String
85 , stIds :: Set.Set String
@@ -390,6 +390,12 @@ blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
390 blockToMarkdown opts (Para [Image attr alt (src,tit)])
390 blockToMarkdown opts (Para [Image attr alt (src,tit)])
391blockToMarkdown' opts (Para inlines) =
391blockToMarkdown' opts (Para inlines) =
392 (<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
392 (<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
393+blockToMarkdown' opts (LineBlock lns) =
394+ if isEnabled Ext_line_blocks opts
395+ then do
396+ mdLines <- mapM (inlineListToMarkdown opts) lns
397+ return $ (vcat $ map (hang 2 (text "| ")) mdLines) <> blankline
398+ else blockToMarkdown opts $ linesToPara lns
393blockToMarkdown' opts (RawBlock f str)
399blockToMarkdown' opts (RawBlock f str)
394 | f == "markdown" = return $ text str <> text "\n"
400 | f == "markdown" = return $ text str <> text "\n"
395 | f == "html" && isEnabled Ext_raw_html opts = do
401 | f == "html" && isEnabled Ext_raw_html opts = do
src/Text/Pandoc/Writers/MediaWiki.hs+3
@@ -120,6 +120,9 @@ blockToMediaWiki (Para inlines) = do
120 then "<p>" ++ contents ++ "</p>"
120 then "<p>" ++ contents ++ "</p>"
121 else contents ++ if null lev then "\n" else ""
121 else contents ++ if null lev then "\n" else ""
122
122
123+blockToMediaWiki (LineBlock lns) =
124+ blockToMediaWiki $ linesToPara lns
125+
123blockToMediaWiki (RawBlock f str)
126blockToMediaWiki (RawBlock f str)
124 | f == Format "mediawiki" = return str
127 | f == Format "mediawiki" = return str
125 | f == Format "html" = return str
128 | f == Format "html" = return str
src/Text/Pandoc/Writers/Native.hs+2
@@ -45,6 +45,8 @@ prettyList ds =
45
45
46-- | Prettyprint Pandoc block element.
46-- | Prettyprint Pandoc block element.
47prettyBlock :: Block -> Doc
47prettyBlock :: Block -> Doc
48+prettyBlock (LineBlock lines') =
49+ "LineBlock" $$ prettyList (map (text . show) lines')
48prettyBlock (BlockQuote blocks) =
50prettyBlock (BlockQuote blocks) =
49 "BlockQuote" $$ prettyList (map prettyBlock blocks)
51 "BlockQuote" $$ prettyList (map prettyBlock blocks)
50prettyBlock (OrderedList attribs blockLists) =
52prettyBlock (OrderedList attribs blockLists) =
src/Text/Pandoc/Writers/OpenDocument.hs+2
@@ -33,6 +33,7 @@ module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Options
34import Text.Pandoc.Options
35import Text.Pandoc.XML
35import Text.Pandoc.XML
36+import Text.Pandoc.Shared (linesToPara)
36import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Readers.TeXMath
38import Text.Pandoc.Readers.TeXMath
38import Text.Pandoc.Pretty
39import Text.Pandoc.Pretty
@@ -291,6 +292,7 @@ blockToOpenDocument o bs
291 | Para b <- bs = if null b
292 | Para b <- bs = if null b
292 then return empty
293 then return empty
293 else inParagraphTags =<< inlinesToOpenDocument o b
294 else inParagraphTags =<< inlinesToOpenDocument o b
295+ | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
294 | Div _ xs <- bs = blocksToOpenDocument o xs
296 | Div _ xs <- bs = blocksToOpenDocument o xs
295 | Header i _ b <- bs = setFirstPara >>
297 | Header i _ b <- bs = setFirstPara >>
296 (inHeaderTags i =<< inlinesToOpenDocument o b)
298 (inHeaderTags i =<< inlinesToOpenDocument o b)
src/Text/Pandoc/Writers/Org.hs+11
@@ -164,6 +164,17 @@ blockToOrg (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
164blockToOrg (Para inlines) = do
164blockToOrg (Para inlines) = do
165 contents <- inlineListToOrg inlines
165 contents <- inlineListToOrg inlines
166 return $ contents <> blankline
166 return $ contents <> blankline
167+blockToOrg (LineBlock lns) = do
168+ let splitStanza [] = []
169+ splitStanza xs = case break (== mempty) xs of
170+ (l, []) -> l : []
171+ (l, _:r) -> l : splitStanza r
172+ let joinWithLinefeeds = nowrap . mconcat . intersperse cr
173+ let joinWithBlankLines = mconcat . intersperse blankline
174+ let prettyfyStanza ls = joinWithLinefeeds <$> mapM inlineListToOrg ls
175+ contents <- joinWithBlankLines <$> mapM prettyfyStanza (splitStanza lns)
176+ return $ blankline $$ "#+BEGIN_VERSE" $$
177+ nest 2 contents $$ "#+END_VERSE" <> blankline
167blockToOrg (RawBlock "html" str) =
178blockToOrg (RawBlock "html" str) =
168 return $ blankline $$ "#+BEGIN_HTML" $$
179 return $ blankline $$ "#+BEGIN_HTML" $$
169 nest 2 (text str) $$ "#+END_HTML" $$ blankline
180 nest 2 (text str) $$ "#+END_HTML" $$ blankline
src/Text/Pandoc/Writers/RST.hs+9−2
@@ -201,11 +201,12 @@ blockToRST (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
201 return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
201 return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
202blockToRST (Para inlines)
202blockToRST (Para inlines)
203 | LineBreak `elem` inlines = do -- use line block if LineBreaks
203 | LineBreak `elem` inlines = do -- use line block if LineBreaks
204− lns <- mapM inlineListToRST $ splitBy (==LineBreak) inlines
204+ linesToLineBlock $ splitBy (==LineBreak) inlines
205− return $ (vcat $ map (hang 2 (text "| ")) lns) <> blankline
206 | otherwise = do
205 | otherwise = do
207 contents <- inlineListToRST inlines
206 contents <- inlineListToRST inlines
208 return $ contents <> blankline
207 return $ contents <> blankline
208+blockToRST (LineBlock lns) =
209+ linesToLineBlock lns
209blockToRST (RawBlock f@(Format f') str)
210blockToRST (RawBlock f@(Format f') str)
210 | f == "rst" = return $ text str
211 | f == "rst" = return $ text str
211 | otherwise = return $ blankline <> ".. raw:: " <>
212 | otherwise = return $ blankline <> ".. raw:: " <>
@@ -328,6 +329,12 @@ definitionListItemToRST (label, defs) = do
328 tabstop <- get >>= (return . writerTabStop . stOptions)
329 tabstop <- get >>= (return . writerTabStop . stOptions)
329 return $ label' $$ nest tabstop (nestle contents <> cr)
330 return $ label' $$ nest tabstop (nestle contents <> cr)
330
331
332+-- | Format a list of lines as line block.
333+linesToLineBlock :: [[Inline]] -> State WriterState Doc
334+linesToLineBlock inlineLines = do
335+ lns <- mapM inlineListToRST inlineLines
336+ return $ (vcat $ map (hang 2 (text "| ")) lns) <> blankline
337+
331-- | Convert list of Pandoc block elements to RST.
338-- | Convert list of Pandoc block elements to RST.
332blockListToRST' :: Bool
339blockListToRST' :: Bool
333 -> [Block] -- ^ List of block elements
340 -> [Block] -- ^ List of block elements
src/Text/Pandoc/Writers/RTF.hs+2
@@ -233,6 +233,8 @@ blockToRTF indent alignment (Plain lst) =
233 rtfCompact indent 0 alignment $ inlineListToRTF lst
233 rtfCompact indent 0 alignment $ inlineListToRTF lst
234blockToRTF indent alignment (Para lst) =
234blockToRTF indent alignment (Para lst) =
235 rtfPar indent 0 alignment $ inlineListToRTF lst
235 rtfPar indent 0 alignment $ inlineListToRTF lst
236+blockToRTF indent alignment (LineBlock lns) =
237+ blockToRTF indent alignment $ linesToPara lns
236blockToRTF indent alignment (BlockQuote lst) =
238blockToRTF indent alignment (BlockQuote lst) =
237 concatMap (blockToRTF (indent + indentIncrement) alignment) lst
239 concatMap (blockToRTF (indent + indentIncrement) alignment) lst
238blockToRTF indent _ (CodeBlock _ str) =
240blockToRTF indent _ (CodeBlock _ str) =
src/Text/Pandoc/Writers/TEI.hs+8−7
@@ -108,7 +108,7 @@ plainToPara :: Block -> Block
108plainToPara (Plain x) = Para x
108plainToPara (Plain x) = Para x
109plainToPara x = x
109plainToPara x = x
110
110
111−-- | Convert a list of pairs of terms and definitions into a TEI
111+-- | Convert a list of pairs of terms and definitions into a TEI
112-- list with labels and items.
112-- list with labels and items.
113deflistItemsToTEI :: WriterOptions -> [([Inline],[[Block]])] -> Doc
113deflistItemsToTEI :: WriterOptions -> [([Inline],[[Block]])] -> Doc
114deflistItemsToTEI opts items =
114deflistItemsToTEI opts items =
@@ -167,6 +167,8 @@ blockToTEI opts (Plain lst) = blockToTEI opts $ Para lst
167-- inTagsSimple "textobject" (inTagsSimple "phrase" alt))
167-- inTagsSimple "textobject" (inTagsSimple "phrase" alt))
168blockToTEI opts (Para lst) =
168blockToTEI opts (Para lst) =
169 inTags False "p" [] $ inlinesToTEI opts lst
169 inTags False "p" [] $ inlinesToTEI opts lst
170+blockToTEI opts (LineBlock lns) =
171+ blockToTEI opts $ linesToPara lns
170blockToTEI opts (BlockQuote blocks) =
172blockToTEI opts (BlockQuote blocks) =
171 inTagsIndented "quote" $ blocksToTEI opts blocks
173 inTagsIndented "quote" $ blocksToTEI opts blocks
172blockToTEI _ (CodeBlock (_,classes,_) str) =
174blockToTEI _ (CodeBlock (_,classes,_) str) =
@@ -174,7 +176,7 @@ blockToTEI _ (CodeBlock (_,classes,_) str) =
174 flush (text (escapeStringForXML str) <> cr <> text "</ab>")
176 flush (text (escapeStringForXML str) <> cr <> text "</ab>")
175 where lang = if null langs
177 where lang = if null langs
176 then ""
178 then ""
177− else escapeStringForXML (head langs)
179+ else escapeStringForXML (head langs)
178 isLang l = map toLower l `elem` map (map toLower) languages
180 isLang l = map toLower l `elem` map (map toLower) languages
179 langsFrom s = if isLang s
181 langsFrom s = if isLang s
180 then [s]
182 then [s]
@@ -210,7 +212,7 @@ blockToTEI _ HorizontalRule =
210 selfClosingTag "milestone" [("unit","undefined"), ("type","separator"),("rendition","line")]
212 selfClosingTag "milestone" [("unit","undefined"), ("type","separator"),("rendition","line")]
211
213
212-- | TEI Tables
214-- | TEI Tables
213−-- TEI Simple's tables are composed of cells and rows; other
215+-- TEI Simple's tables are composed of cells and rows; other
214-- table info in the AST is here lossily discard.
216-- table info in the AST is here lossily discard.
215blockToTEI opts (Table _ _ _ headers rows) =
217blockToTEI opts (Table _ _ _ headers rows) =
216 let
218 let
@@ -219,8 +221,8 @@ blockToTEI opts (Table _ _ _ headers rows) =
219-- then return empty
221-- then return empty
220-- else tableRowToTEI opts headers
222-- else tableRowToTEI opts headers
221 in
223 in
222− inTags True "table" [] $
224+ inTags True "table" [] $
223− vcat $ [headers'] <> map (tableRowToTEI opts) rows
225+ vcat $ [headers'] <> map (tableRowToTEI opts) rows
224
226
225tableRowToTEI :: WriterOptions
227tableRowToTEI :: WriterOptions
226 -> [[Block]]
228 -> [[Block]]
@@ -276,7 +278,7 @@ inlineToTEI _ (Math t str) =
276 text (str)
278 text (str)
277 DisplayMath -> inTags True "figure" [("type","math")] $
279 DisplayMath -> inTags True "figure" [("type","math")] $
278 inTags False "formula" [("notation","TeX")] $ text (str)
280 inTags False "formula" [("notation","TeX")] $ text (str)
279−
281+
280inlineToTEI _ (RawInline f x) | f == "tei" = text x
282inlineToTEI _ (RawInline f x) | f == "tei" = text x
281 | otherwise = empty
283 | otherwise = empty
282inlineToTEI _ LineBreak = selfClosingTag "lb" []
284inlineToTEI _ LineBreak = selfClosingTag "lb" []
@@ -317,4 +319,3 @@ idAndRole (id',cls,_) = ident ++ role
317 role = if null cls
319 role = if null cls
318 then []
320 then []
319 else [("role", unwords cls)]
321 else [("role", unwords cls)]
320−
src/Text/Pandoc/Writers/Texinfo.hs+3
@@ -145,6 +145,9 @@ blockToTexinfo (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
145blockToTexinfo (Para lst) =
145blockToTexinfo (Para lst) =
146 inlineListToTexinfo lst -- this is handled differently from Plain in blockListToTexinfo
146 inlineListToTexinfo lst -- this is handled differently from Plain in blockListToTexinfo
147
147
148+blockToTexinfo (LineBlock lns) =
149+ blockToTexinfo $ linesToPara lns
150+
148blockToTexinfo (BlockQuote lst) = do
151blockToTexinfo (BlockQuote lst) = do
149 contents <- blockListToTexinfo lst
152 contents <- blockListToTexinfo lst
150 return $ text "@quotation" $$
153 return $ text "@quotation" $$
src/Text/Pandoc/Writers/Textile.hs+3
@@ -130,6 +130,9 @@ blockToTextile opts (Para inlines) = do
130 then "<p>" ++ contents ++ "</p>"
130 then "<p>" ++ contents ++ "</p>"
131 else contents ++ if null listLevel then "\n" else ""
131 else contents ++ if null listLevel then "\n" else ""
132
132
133+blockToTextile opts (LineBlock lns) =
134+ blockToTextile opts $ linesToPara lns
135+
133blockToTextile _ (RawBlock f str)
136blockToTextile _ (RawBlock f str)
134 | f == Format "html" || f == Format "textile" = return str
137 | f == Format "html" || f == Format "textile" = return str
135 | otherwise = return ""
138 | otherwise = return ""
src/Text/Pandoc/Writers/ZimWiki.hs+5−1
@@ -33,7 +33,8 @@ http://zim-wiki.org/manual/Help/Wiki_Syntax.html
33module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
33module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
35import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
36−import Text.Pandoc.Shared ( escapeURI, removeFormatting, trimr, substitute )
36+import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting, trimr
37+ , substitute )
37import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
38import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
38import Text.Pandoc.ImageSize
39import Text.Pandoc.ImageSize
39import Text.Pandoc.Templates ( renderTemplate' )
40import Text.Pandoc.Templates ( renderTemplate' )
@@ -111,6 +112,9 @@ blockToZimWiki opts (Para inlines) = do
111 contents <- inlineListToZimWiki opts inlines
112 contents <- inlineListToZimWiki opts inlines
112 return $ contents ++ if null indent then "\n" else ""
113 return $ contents ++ if null indent then "\n" else ""
113
114
115+blockToZimWiki opts (LineBlock lns) = do
116+ blockToZimWiki opts $ linesToPara lns
117+
114blockToZimWiki opts (RawBlock f str)
118blockToZimWiki opts (RawBlock f str)
115 | f == Format "zimwiki" = return str
119 | f == Format "zimwiki" = return str
116 | f == Format "html" = do cont <- indentFromHTML opts str; return cont
120 | f == Format "html" = do cont <- indentFromHTML opts str; return cont