git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3072 from tarleb/lineblock

Read and write LineBlock elements

commit4eff6076788d6852974985a0bfcbf73c4d12244e authorJohn MacFarlane <jgm@berkeley.edu> dateThu 13 Oct 2016, 11:38 (10 years ago) parentcbeb72d63966f6
35 files changed+157−61
pandoc.cabal+5−5 src/Text/Pandoc/Parsing.hs+5−2 src/Text/Pandoc/Readers/DocBook.hs+3−3 src/Text/Pandoc/Readers/Markdown.hs+2−2 src/Text/Pandoc/Readers/Org/Blocks.hs+2−2 src/Text/Pandoc/Readers/RST.hs+2−2 src/Text/Pandoc/Shared.hs+11 src/Text/Pandoc/Writers/AsciiDoc.hs+7−1 src/Text/Pandoc/Writers/CommonMark.hs+2−1 src/Text/Pandoc/Writers/ConTeXt.hs+3−1 src/Text/Pandoc/Writers/Custom.hs+2 src/Text/Pandoc/Writers/Docbook.hs+2−1 src/Text/Pandoc/Writers/Docx.hs+5−6 src/Text/Pandoc/Writers/DokuWiki.hs+5−2 src/Text/Pandoc/Writers/FB2.hs+3−1 src/Text/Pandoc/Writers/HTML.hs+8−1 src/Text/Pandoc/Writers/Haddock.hs+2 src/Text/Pandoc/Writers/ICML.hs+4−2 src/Text/Pandoc/Writers/LaTeX.hs+2 src/Text/Pandoc/Writers/Man.hs+2−1 src/Text/Pandoc/Writers/Markdown.hs+7−1 src/Text/Pandoc/Writers/MediaWiki.hs+3 src/Text/Pandoc/Writers/Native.hs+2 src/Text/Pandoc/Writers/OpenDocument.hs+2 src/Text/Pandoc/Writers/Org.hs+11 src/Text/Pandoc/Writers/RST.hs+9−2 src/Text/Pandoc/Writers/RTF.hs+2 src/Text/Pandoc/Writers/TEI.hs+8−7 src/Text/Pandoc/Writers/Texinfo.hs+3 src/Text/Pandoc/Writers/Textile.hs+3 src/Text/Pandoc/Writers/ZimWiki.hs+5−1 tests/Tests/Readers/Org.hs+7−10 tests/Tests/Readers/RST.hs+2−3 tests/markdown-reader-more.native+8−2 tests/rst-reader.native+8−2
pandoc.cabal+5−5
@@ -205,8 +205,8 @@ Extra-Source-Files:
205205 tests/lhs-test.html+lhs
206206 tests/lhs-test.fragment.html+lhs
207207 tests/pipe-tables.txt
208− tests/dokuwiki_external_images.dokuwiki
209− tests/dokuwiki_external_images.native
208+ tests/dokuwiki_external_images.dokuwiki
209+ tests/dokuwiki_external_images.native
210210 tests/dokuwiki_multiblock_table.dokuwiki
211211 tests/dokuwiki_multiblock_table.native
212212 tests/fb2/*.markdown
@@ -267,7 +267,7 @@ Library
267267 xml >= 1.3.12 && < 1.4,
268268 random >= 1 && < 1.2,
269269 extensible-exceptions >= 0.1 && < 0.2,
270− pandoc-types >= 1.16 && < 1.17,
270+ pandoc-types >= 1.17 && < 1.18,
271271 aeson >= 0.7 && < 1.1,
272272 tagsoup >= 0.13.7 && < 0.15,
273273 base64-bytestring >= 0.1 && < 1.1,
@@ -422,7 +422,7 @@ Library
422422
423423Executable pandoc
424424 Build-Depends: pandoc,
425− pandoc-types >= 1.16 && < 1.17,
425+ pandoc-types >= 1.17 && < 1.18,
426426 base >= 4.2 && <5,
427427 directory >= 1.2 && < 1.3,
428428 filepath >= 1.1 && < 1.5,
@@ -479,7 +479,7 @@ Test-Suite test-pandoc
479479 Build-Depends: base >= 4.2 && < 5,
480480 syb >= 0.1 && < 0.7,
481481 pandoc,
482− pandoc-types >= 1.16 && < 1.17,
482+ pandoc-types >= 1.17 && < 1.18,
483483 bytestring >= 0.9 && < 0.11,
484484 text >= 0.11 && < 1.3,
485485 directory >= 1 && < 1.3,
src/Text/Pandoc/Parsing.hs+5−2
@@ -718,11 +718,14 @@ lineBlockLine = try $ do
718718 continuations <- many (try $ char ' ' >> anyLine)
719719 return $ white ++ unwords (line : continuations)
720720
721+blankLineBlockLine :: Stream [Char] m Char => ParserT [Char] st m Char
722+blankLineBlockLine = try (char '|' >> blankline)
723+
721724-- | Parses an RST-style line block and returns a list of strings.
722725lineBlockLines :: Stream [Char] m Char => ParserT [Char] st m [String]
723726lineBlockLines = try $ do
724− lines' <- many1 lineBlockLine
725− skipMany1 $ blankline <|> try (char '|' >> blankline)
727+ lines' <- many1 (lineBlockLine <|> ((:[]) <$> blankLineBlockLine))
728+ skipMany1 $ blankline <|> blankLineBlockLine
726729 return lines'
727730
728731-- | Parse a table using 'headerParser', 'rowParser',
src/Text/Pandoc/Readers/DocBook.hs+3−3
@@ -592,8 +592,6 @@ checkInMeta p = do
592592 when accepts p
593593 return mempty
594594
595−
596−
597595addMeta :: ToMetaValue a => String -> a -> DB ()
598596addMeta field val = modify (setMeta field val)
599597
@@ -612,7 +610,7 @@ isBlockElement (Elem e) = qName (elName e) `elem` blocktags
612610 "important","caution","note","tip","warning","qandadiv",
613611 "question","answer","abstract","itemizedlist","orderedlist",
614612 "variablelist","article","book","table","informaltable",
615− "informalexample",
613+ "informalexample", "linegroup",
616614 "screen","programlisting","example","calloutlist"]
617615isBlockElement _ = False
618616
@@ -779,6 +777,7 @@ parseBlock (Elem e) =
779777 "informaltable" -> parseTable
780778 "informalexample" -> divWith ("", ["informalexample"], []) <$>
781779 getBlocks e
780+ "linegroup" -> lineBlock <$> lineItems
782781 "literallayout" -> codeBlockWithLang
783782 "screen" -> codeBlockWithLang
784783 "programlisting" -> codeBlockWithLang
@@ -900,6 +899,7 @@ parseBlock (Elem e) =
900899 let ident = attrValue "id" e
901900 modify $ \st -> st{ dbSectionLevel = n - 1 }
902901 return $ headerWith (ident,[],[]) n' headerText <> b
902+ lineItems = mapM getInlines $ filterChildren (named "line") e
903903 metaBlock = acceptingMetadata (getBlocks e) >> return mempty
904904
905905getInlines :: Element -> DB Inlines
src/Text/Pandoc/Readers/Markdown.hs+2−2
@@ -32,7 +32,7 @@ Conversion of markdown-formatted plain text to 'Pandoc' document.
3232module Text.Pandoc.Readers.Markdown ( readMarkdown,
3333 readMarkdownWithWarnings ) where
3434
35−import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
35+import Data.List ( transpose, sortBy, findIndex, intercalate )
3636import qualified Data.Map as M
3737import Data.Scientific (coefficient, base10Exponent)
3838import Data.Ord ( comparing )
@@ -1106,7 +1106,7 @@ lineBlock = try $ do
11061106 guardEnabled Ext_line_blocks
11071107 lines' <- lineBlockLines >>=
11081108 mapM (parseFromString (trimInlinesF . mconcat <$> many inline))
1109− return $ B.para <$> (mconcat $ intersperse (return B.linebreak) lines')
1109+ return $ B.lineBlock <$> sequence lines'
11101110
11111111--
11121112-- Tables
src/Text/Pandoc/Readers/Org/Blocks.hs+2−2
@@ -50,7 +50,7 @@ import Text.Pandoc.Shared ( compactify', compactify'DL )
5050
5151import Control.Monad ( foldM, guard, mzero, void )
5252import Data.Char ( isSpace, toLower, toUpper)
53−import Data.List ( foldl', intersperse, isPrefixOf )
53+import Data.List ( foldl', isPrefixOf )
5454import Data.Maybe ( fromMaybe, isNothing )
5555import Data.Monoid ((<>))
5656
@@ -427,7 +427,7 @@ verseBlock :: String -> OrgParser (F Blocks)
427427verseBlock blockType = try $ do
428428 ignHeaders
429429 content <- rawBlockContent blockType
430− fmap B.para . mconcat . intersperse (pure B.linebreak)
430+ fmap B.lineBlock . sequence
431431 <$> mapM parseVerseLine (lines content)
432432 where
433433 -- replace initial spaces with nonbreaking spaces to preserve
src/Text/Pandoc/Readers/RST.hs+2−2
@@ -39,7 +39,7 @@ import Text.Pandoc.Shared
3939import Text.Pandoc.Parsing
4040import Text.Pandoc.Options
4141import Control.Monad ( when, liftM, guard, mzero )
42−import Data.List ( findIndex, intersperse, intercalate,
42+import Data.List ( findIndex, intercalate,
4343 transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
4444import Data.Maybe (fromMaybe)
4545import qualified Data.Map as M
@@ -228,7 +228,7 @@ lineBlock :: RSTParser Blocks
228228lineBlock = try $ do
229229 lines' <- lineBlockLines
230230 lines'' <- mapM parseInlineFromString lines'
231− return $ B.para (mconcat $ intersperse B.linebreak lines'')
231+ return $ B.lineBlock lines''
232232
233233--
234234-- paragraph block
src/Text/Pandoc/Shared.hs+11
@@ -64,6 +64,7 @@ module Text.Pandoc.Shared (
6464 compactify,
6565 compactify',
6666 compactify'DL,
67+ linesToPara,
6768 Element (..),
6869 hierarchicalize,
6970 uniqueIdent,
@@ -630,6 +631,15 @@ compactify'DL items =
630631 | otherwise -> items
631632 _ -> items
632633
634+-- | Combine a list of lines by adding hard linebreaks.
635+combineLines :: [[Inline]] -> [Inline]
636+combineLines = intercalate [LineBreak]
637+
638+-- | Convert a list of lines into a paragraph with hard line breaks. This is
639+-- useful e.g. for rudimentary support of LineBlock elements in writers.
640+linesToPara :: [[Inline]] -> Block
641+linesToPara = Para . combineLines
642+
633643isPara :: Block -> Bool
634644isPara (Para _) = True
635645isPara _ = False
@@ -1035,6 +1045,7 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
10351045blockToInlines :: Block -> [Inline]
10361046blockToInlines (Plain ils) = ils
10371047blockToInlines (Para ils) = ils
1048+blockToInlines (LineBlock lns) = combineLines lns
10381049blockToInlines (CodeBlock attr str) = [Code attr str]
10391050blockToInlines (RawBlock fmt str) = [RawInline fmt str]
10401051blockToInlines (BlockQuote blks) = blocksToInlines blks
src/Text/Pandoc/Writers/AsciiDoc.hs+7−1
@@ -137,6 +137,13 @@ blockToAsciiDoc opts (Para inlines) = do
137137 then text "\\"
138138 else empty
139139 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
140147blockToAsciiDoc _ (RawBlock f s)
141148 | f == "asciidoc" = return $ text s
142149 | otherwise = return empty
@@ -459,4 +466,3 @@ inlineToAsciiDoc opts (Span (ident,_,_) ils) = do
459466 let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
460467 contents <- inlineListToAsciiDoc opts ils
461468 return $ identifier <> contents
462−
src/Text/Pandoc/Writers/CommonMark.hs+2−1
@@ -33,7 +33,7 @@ module Text.Pandoc.Writers.CommonMark (writeCommonMark) where
3333
3434import Text.Pandoc.Writers.HTML (writeHtmlString)
3535import Text.Pandoc.Definition
36−import Text.Pandoc.Shared (isTightList)
36+import Text.Pandoc.Shared (isTightList, linesToPara)
3737import Text.Pandoc.Templates (renderTemplate')
3838import Text.Pandoc.Writers.Shared
3939import Text.Pandoc.Options
@@ -94,6 +94,7 @@ blocksToNodes = foldr blockToNodes []
9494blockToNodes :: Block -> [Node] -> [Node]
9595blockToNodes (Plain xs) = (node PARAGRAPH (inlinesToNodes xs) :)
9696blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
97+blockToNodes (LineBlock lns) = blockToNodes $ linesToPara lns
9798blockToNodes (CodeBlock (_,classes,_) xs) =
9899 (node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
99100blockToNodes (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
163163blockToConTeXt (Para lst) = do
164164 contents <- inlineListToConTeXt lst
165165 return $ contents <> blankline
166+blockToConTeXt (LineBlock lns) = do
167+ doclines <- nowrap . vcat <$> mapM inlineListToConTeXt lns
168+ return $ "\\startlines" $$ doclines $$ "\\stoplines" <> blankline
166169blockToConTeXt (BlockQuote lst) = do
167170 contents <- blockListToConTeXt lst
168171 return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
@@ -467,4 +470,3 @@ fromBcp47 x = fromIso $ head x
467470 fromIso "vi" = "vn"
468471 fromIso "zh" = "cn"
469472 fromIso l = l
470−
src/Text/Pandoc/Writers/Custom.hs+2
@@ -227,6 +227,8 @@ blockToCustom lua (Para [Image attr txt (src,tit)]) =
227227
228228blockToCustom lua (Para inlines) = callfunc lua "Para" inlines
229229
230+blockToCustom lua (LineBlock linesList) = callfunc lua "LineBlock" linesList
231+
230232blockToCustom lua (RawBlock format str) =
231233 callfunc lua "RawBlock" format str
232234
src/Text/Pandoc/Writers/Docbook.hs+2−1
@@ -198,6 +198,8 @@ blockToDocbook opts (Para [Image attr txt (src,'f':'i':'g':':':_)]) =
198198blockToDocbook opts (Para lst)
199199 | hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
200200 | otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
201+blockToDocbook opts (LineBlock lns) =
202+ blockToDocbook opts $ linesToPara lns
201203blockToDocbook opts (BlockQuote blocks) =
202204 inTagsIndented "blockquote" $ blocksToDocbook opts blocks
203205blockToDocbook _ (CodeBlock (_,classes,_) str) =
@@ -385,4 +387,3 @@ idAndRole (id',cls,_) = ident ++ role
385387 role = if null cls
386388 then []
387389 else [("role", unwords cls)]
388−
src/Text/Pandoc/Writers/Docx.hs+5−6
@@ -275,7 +275,7 @@ writeDocx opts doc@(Pandoc meta _) = do
275275 }
276276
277277
278− ((contents, footnotes), st) <- runStateT
278+ ((contents, footnotes), st) <- runStateT
279279 (runReaderT
280280 (writeOpenXML opts{writerWrapText = WrapNone} doc')
281281 env)
@@ -446,7 +446,7 @@ writeDocx opts doc@(Pandoc meta _) = do
446446
447447 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
448448 map newTextPropToOpenXml newDynamicTextProps ++
449− (styleToOpenXml styleMaps $ writerHighlightStyle opts)
449+ (styleToOpenXml styleMaps $ writerHighlightStyle opts)
450450 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
451451 where
452452 modifyContent
@@ -859,6 +859,7 @@ blockToOpenXML' opts (Para lst) = do
859859 modify $ \s -> s { stFirstPara = False }
860860 contents <- inlinesToOpenXML opts lst
861861 return [mknode "w:p" [] (paraProps' ++ contents)]
862+blockToOpenXML' opts (LineBlock lns) = blockToOpenXML opts $ linesToPara lns
862863blockToOpenXML' _ (RawBlock format str)
863864 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
864865 | otherwise = return []
@@ -1032,7 +1033,7 @@ setFirstPara = modify $ \s -> s { stFirstPara = True }
10321033
10331034-- | Convert an inline element to OpenXML.
10341035inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
1035−inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
1036+inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
10361037
10371038inlineToOpenXML' :: WriterOptions -> Inline -> WS [Element]
10381039inlineToOpenXML' _ (Str str) = formattedString str
@@ -1286,7 +1287,7 @@ withDirection x = do
12861287 textProps <- asks envTextProperties
12871288 -- We want to clean all bidirection (bidi) and right-to-left (rtl)
12881289 -- properties from the props first. This is because we don't want
1289− -- them to stack up.
1290+ -- them to stack up.
12901291 let paraProps' = filter (\e -> (qName . elName) e /= "bidi") paraProps
12911292 textProps' = filter (\e -> (qName . elName) e /= "rtl") textProps
12921293 if isRTL
@@ -1298,5 +1299,3 @@ withDirection x = do
12981299 else flip local x $ \env -> env { envParaProperties = paraProps'
12991300 , envTextProperties = textProps'
13001301 }
1301−
1302−
src/Text/Pandoc/Writers/DokuWiki.hs+5−2
@@ -45,8 +45,8 @@ import Text.Pandoc.Options ( WriterOptions(
4545 , writerStandalone
4646 , writerTemplate
4747 , writerWrapText), WrapOption(..) )
48−import Text.Pandoc.Shared ( escapeURI, removeFormatting, camelCaseToHyphenated
49− , trimr, normalize, substitute )
48+import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
49+ , camelCaseToHyphenated, trimr, normalize, substitute )
5050import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
5151import Text.Pandoc.ImageSize
5252import Text.Pandoc.Templates ( renderTemplate' )
@@ -147,6 +147,9 @@ blockToDokuWiki opts (Para inlines) = do
147147 then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
148148 else contents ++ if null indent then "\n" else ""
149149
150+blockToDokuWiki opts (LineBlock lns) =
151+ blockToDokuWiki opts $ linesToPara lns
152+
150153blockToDokuWiki _ (RawBlock f str)
151154 | f == Format "dokuwiki" = return str
152155 -- 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
4646
4747import Text.Pandoc.Definition
4848import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
49−import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize)
49+import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
50+ linesToPara)
5051
5152-- | Data to be written at the end of the document:
5253-- (foot)notes, URLs, references, images.
@@ -323,6 +324,7 @@ blockToXml (RawBlock _ s) = return . spaceBeforeAfter .
323324 map (el "p" . el "code") . lines $ s
324325blockToXml (Div _ bs) = cMapM blockToXml bs
325326blockToXml (BlockQuote bs) = liftM (list . el "cite") $ cMapM blockToXml bs
327+blockToXml (LineBlock lns) = blockToXml $ linesToPara lns
326328blockToXml (OrderedList a bss) = do
327329 state <- get
328330 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
463463blockToHtml opts (Para lst) = do
464464 contents <- inlineListToHtml opts lst
465465 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
466473blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
467474 let speakerNotes = "notes" `elem` classes
468475 -- we don't want incremental output inside speaker notes, see #1394
@@ -807,7 +814,7 @@ inlineToHtml opts inline =
807814 let brtag = if writerHtml5 opts then H5.br else H.br
808815 return $ case t of
809816 InlineMath -> m
810− DisplayMath -> brtag >> m >> brtag
817+ DisplayMath -> brtag >> m >> brtag
811818 (RawInline f str)
812819 | f == Format "html" -> return $ preEscapedString str
813820 | 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)]) =
108108blockToHaddock opts (Para inlines) =
109109 -- TODO: if it contains linebreaks, we need to use a @...@ block
110110 (<> blankline) `fmap` blockToHaddock opts (Plain inlines)
111+blockToHaddock opts (LineBlock lns) =
112+ blockToHaddock opts $ linesToPara lns
111113blockToHaddock _ (RawBlock f str)
112114 | f == "haddock" = do
113115 return $ text str <> text "\n"
src/Text/Pandoc/Writers/ICML.hs+4−2
@@ -2,7 +2,7 @@
22
33{- |
44 Module : Text.Pandoc.Writers.ICML
5− Copyright : Copyright (C) 2013 github.com/mb21
5+ Copyright : Copyright (C) 2013-2016 github.com/mb21
66 License : GNU GPL, version 2 or above
77
88 Stability : alpha
@@ -18,7 +18,7 @@ import Text.Pandoc.Definition
1818import Text.Pandoc.XML
1919import Text.Pandoc.Readers.TeXMath (texMathToInlines)
2020import Text.Pandoc.Writers.Shared
21−import Text.Pandoc.Shared (splitBy, fetchItem, warn)
21+import Text.Pandoc.Shared (linesToPara, splitBy, fetchItem, warn)
2222import Text.Pandoc.Options
2323import Text.Pandoc.Templates (renderTemplate')
2424import Text.Pandoc.Pretty
@@ -297,6 +297,8 @@ blockToICML opts style (Para img@[Image _ txt (_,'f':'i':'g':':':_)]) = do
297297 caption <- parStyle opts (imgCaptionName:style) txt
298298 return $ intersperseBrs [figure, caption]
299299blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
300+blockToICML opts style (LineBlock lns) =
301+ blockToICML opts style $ linesToPara lns
300302blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
301303blockToICML _ _ (RawBlock f str)
302304 | 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
437437 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
438438blockToLaTeX (Para lst) =
439439 inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
440+blockToLaTeX (LineBlock lns) = do
441+ blockToLaTeX $ linesToPara lns
440442blockToLaTeX (BlockQuote lst) = do
441443 beamer <- writerBeamer `fmap` gets stOptions
442444 case lst of
src/Text/Pandoc/Writers/Man.hs+2−1
@@ -171,6 +171,8 @@ blockToMan opts (Para inlines) = do
171171 contents <- liftM vcat $ mapM (inlineListToMan opts) $
172172 splitSentences inlines
173173 return $ text ".PP" $$ contents
174+blockToMan opts (LineBlock lns) =
175+ blockToMan opts $ linesToPara lns
174176blockToMan _ (RawBlock f str)
175177 | f == Format "man" = return $ text str
176178 | otherwise = return empty
@@ -367,4 +369,3 @@ inlineToMan _ (Note contents) = do
367369 notes <- liftM stNotes get
368370 let ref = show $ (length notes)
369371 return $ char '[' <> text ref <> char ']'
370−
src/Text/Pandoc/Writers/Markdown.hs+7−1
@@ -79,7 +79,7 @@ instance Default WriterEnv
7979 , envRefShortcutable = True
8080 , envBlockLevel = 0
8181 }
82−
82+
8383data WriterState = WriterState { stNotes :: Notes
8484 , stRefs :: Refs
8585 , stIds :: Set.Set String
@@ -390,6 +390,12 @@ blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
390390 blockToMarkdown opts (Para [Image attr alt (src,tit)])
391391blockToMarkdown' opts (Para inlines) =
392392 (<> 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
393399blockToMarkdown' opts (RawBlock f str)
394400 | f == "markdown" = return $ text str <> text "\n"
395401 | f == "html" && isEnabled Ext_raw_html opts = do
src/Text/Pandoc/Writers/MediaWiki.hs+3
@@ -120,6 +120,9 @@ blockToMediaWiki (Para inlines) = do
120120 then "<p>" ++ contents ++ "</p>"
121121 else contents ++ if null lev then "\n" else ""
122122
123+blockToMediaWiki (LineBlock lns) =
124+ blockToMediaWiki $ linesToPara lns
125+
123126blockToMediaWiki (RawBlock f str)
124127 | f == Format "mediawiki" = return str
125128 | f == Format "html" = return str
src/Text/Pandoc/Writers/Native.hs+2
@@ -45,6 +45,8 @@ prettyList ds =
4545
4646-- | Prettyprint Pandoc block element.
4747prettyBlock :: Block -> Doc
48+prettyBlock (LineBlock lines') =
49+ "LineBlock" $$ prettyList (map (text . show) lines')
4850prettyBlock (BlockQuote blocks) =
4951 "BlockQuote" $$ prettyList (map prettyBlock blocks)
5052prettyBlock (OrderedList attribs blockLists) =
src/Text/Pandoc/Writers/OpenDocument.hs+2
@@ -33,6 +33,7 @@ module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Options
3535import Text.Pandoc.XML
36+import Text.Pandoc.Shared (linesToPara)
3637import Text.Pandoc.Templates (renderTemplate')
3738import Text.Pandoc.Readers.TeXMath
3839import Text.Pandoc.Pretty
@@ -291,6 +292,7 @@ blockToOpenDocument o bs
291292 | Para b <- bs = if null b
292293 then return empty
293294 else inParagraphTags =<< inlinesToOpenDocument o b
295+ | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
294296 | Div _ xs <- bs = blocksToOpenDocument o xs
295297 | Header i _ b <- bs = setFirstPara >>
296298 (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
164164blockToOrg (Para inlines) = do
165165 contents <- inlineListToOrg inlines
166166 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
167178blockToOrg (RawBlock "html" str) =
168179 return $ blankline $$ "#+BEGIN_HTML" $$
169180 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
201201 return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
202202blockToRST (Para inlines)
203203 | LineBreak `elem` inlines = do -- use line block if LineBreaks
204− lns <- mapM inlineListToRST $ splitBy (==LineBreak) inlines
205− return $ (vcat $ map (hang 2 (text "| ")) lns) <> blankline
204+ linesToLineBlock $ splitBy (==LineBreak) inlines
206205 | otherwise = do
207206 contents <- inlineListToRST inlines
208207 return $ contents <> blankline
208+blockToRST (LineBlock lns) =
209+ linesToLineBlock lns
209210blockToRST (RawBlock f@(Format f') str)
210211 | f == "rst" = return $ text str
211212 | otherwise = return $ blankline <> ".. raw:: " <>
@@ -328,6 +329,12 @@ definitionListItemToRST (label, defs) = do
328329 tabstop <- get >>= (return . writerTabStop . stOptions)
329330 return $ label' $$ nest tabstop (nestle contents <> cr)
330331
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+
331338-- | Convert list of Pandoc block elements to RST.
332339blockListToRST' :: Bool
333340 -> [Block] -- ^ List of block elements
src/Text/Pandoc/Writers/RTF.hs+2
@@ -233,6 +233,8 @@ blockToRTF indent alignment (Plain lst) =
233233 rtfCompact indent 0 alignment $ inlineListToRTF lst
234234blockToRTF indent alignment (Para lst) =
235235 rtfPar indent 0 alignment $ inlineListToRTF lst
236+blockToRTF indent alignment (LineBlock lns) =
237+ blockToRTF indent alignment $ linesToPara lns
236238blockToRTF indent alignment (BlockQuote lst) =
237239 concatMap (blockToRTF (indent + indentIncrement) alignment) lst
238240blockToRTF indent _ (CodeBlock _ str) =
src/Text/Pandoc/Writers/TEI.hs+8−7
@@ -108,7 +108,7 @@ plainToPara :: Block -> Block
108108plainToPara (Plain x) = Para x
109109plainToPara x = x
110110
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
112112-- list with labels and items.
113113deflistItemsToTEI :: WriterOptions -> [([Inline],[[Block]])] -> Doc
114114deflistItemsToTEI opts items =
@@ -167,6 +167,8 @@ blockToTEI opts (Plain lst) = blockToTEI opts $ Para lst
167167-- inTagsSimple "textobject" (inTagsSimple "phrase" alt))
168168blockToTEI opts (Para lst) =
169169 inTags False "p" [] $ inlinesToTEI opts lst
170+blockToTEI opts (LineBlock lns) =
171+ blockToTEI opts $ linesToPara lns
170172blockToTEI opts (BlockQuote blocks) =
171173 inTagsIndented "quote" $ blocksToTEI opts blocks
172174blockToTEI _ (CodeBlock (_,classes,_) str) =
@@ -174,7 +176,7 @@ blockToTEI _ (CodeBlock (_,classes,_) str) =
174176 flush (text (escapeStringForXML str) <> cr <> text "</ab>")
175177 where lang = if null langs
176178 then ""
177− else escapeStringForXML (head langs)
179+ else escapeStringForXML (head langs)
178180 isLang l = map toLower l `elem` map (map toLower) languages
179181 langsFrom s = if isLang s
180182 then [s]
@@ -210,7 +212,7 @@ blockToTEI _ HorizontalRule =
210212 selfClosingTag "milestone" [("unit","undefined"), ("type","separator"),("rendition","line")]
211213
212214-- | 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
214216-- table info in the AST is here lossily discard.
215217blockToTEI opts (Table _ _ _ headers rows) =
216218 let
@@ -219,8 +221,8 @@ blockToTEI opts (Table _ _ _ headers rows) =
219221-- then return empty
220222-- else tableRowToTEI opts headers
221223 in
222− inTags True "table" [] $
223− vcat $ [headers'] <> map (tableRowToTEI opts) rows
224+ inTags True "table" [] $
225+ vcat $ [headers'] <> map (tableRowToTEI opts) rows
224226
225227tableRowToTEI :: WriterOptions
226228 -> [[Block]]
@@ -276,7 +278,7 @@ inlineToTEI _ (Math t str) =
276278 text (str)
277279 DisplayMath -> inTags True "figure" [("type","math")] $
278280 inTags False "formula" [("notation","TeX")] $ text (str)
279−
281+
280282inlineToTEI _ (RawInline f x) | f == "tei" = text x
281283 | otherwise = empty
282284inlineToTEI _ LineBreak = selfClosingTag "lb" []
@@ -317,4 +319,3 @@ idAndRole (id',cls,_) = ident ++ role
317319 role = if null cls
318320 then []
319321 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
145145blockToTexinfo (Para lst) =
146146 inlineListToTexinfo lst -- this is handled differently from Plain in blockListToTexinfo
147147
148+blockToTexinfo (LineBlock lns) =
149+ blockToTexinfo $ linesToPara lns
150+
148151blockToTexinfo (BlockQuote lst) = do
149152 contents <- blockListToTexinfo lst
150153 return $ text "@quotation" $$
src/Text/Pandoc/Writers/Textile.hs+3
@@ -130,6 +130,9 @@ blockToTextile opts (Para inlines) = do
130130 then "<p>" ++ contents ++ "</p>"
131131 else contents ++ if null listLevel then "\n" else ""
132132
133+blockToTextile opts (LineBlock lns) =
134+ blockToTextile opts $ linesToPara lns
135+
133136blockToTextile _ (RawBlock f str)
134137 | f == Format "html" || f == Format "textile" = return str
135138 | otherwise = return ""
src/Text/Pandoc/Writers/ZimWiki.hs+5−1
@@ -33,7 +33,8 @@ http://zim-wiki.org/manual/Help/Wiki_Syntax.html
3333module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
3434import Text.Pandoc.Definition
3535import 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 )
3738import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
3839import Text.Pandoc.ImageSize
3940import Text.Pandoc.Templates ( renderTemplate' )
@@ -111,6 +112,9 @@ blockToZimWiki opts (Para inlines) = do
111112 contents <- inlineListToZimWiki opts inlines
112113 return $ contents ++ if null indent then "\n" else ""
113114
115+blockToZimWiki opts (LineBlock lns) = do
116+ blockToZimWiki opts $ linesToPara lns
117+
114118blockToZimWiki opts (RawBlock f str)
115119 | f == Format "zimwiki" = return str
116120 | f == Format "html" = do cont <- indentFromHTML opts str; return cont
tests/Tests/Readers/Org.hs+7−10
@@ -1490,14 +1490,11 @@ tests =
14901490 mconcat
14911491 [ para $ spcSep [ "The", "first", "lines", "of"
14921492 , "Goethe's", emph "Faust" <> ":"]
1493− , para $ mconcat
1494− [ spcSep [ "Habe", "nun,", "ach!", "Philosophie," ]
1495− , linebreak
1496− , spcSep [ "Juristerei", "und", "Medizin," ]
1497− , linebreak
1498− , spcSep [ "Und", "leider", "auch", "Theologie!" ]
1499− , linebreak
1500− , spcSep [ "Durchaus", "studiert,", "mit", "heißem", "Bemühn." ]
1493+ , lineBlock
1494+ [ "Habe nun, ach! Philosophie,"
1495+ , "Juristerei und Medizin,"
1496+ , "Und leider auch Theologie!"
1497+ , "Durchaus studiert, mit heißem Bemühn."
15011498 ]
15021499 ]
15031500
@@ -1508,7 +1505,7 @@ tests =
15081505 , "bar"
15091506 , "#+END_VERSE"
15101507 ] =?>
1511− para ("foo" <> linebreak <> linebreak <> "bar")
1508+ lineBlock [ "foo", mempty, "bar" ]
15121509
15131510 , "Verse block with varying indentation" =:
15141511 unlines [ "#+BEGIN_VERSE"
@@ -1516,7 +1513,7 @@ tests =
15161513 , "my old friend"
15171514 , "#+END_VERSE"
15181515 ] =?>
1519− para ("\160\160hello darkness" <> linebreak <> "my old friend")
1516+ lineBlock [ "\160\160hello darkness", "my old friend" ]
15201517
15211518 , "Raw block LaTeX" =:
15221519 unlines [ "#+BEGIN_LaTeX"
tests/Tests/Readers/RST.hs+2−3
@@ -19,8 +19,7 @@ infix 4 =:
1919
2020tests :: [Test]
2121tests = [ "line block with blank line" =:
22− "| a\n|\n| b" =?> para (str "a") <>
23− para (str "\160b")
22+ "| a\n|\n| b" =?> lineBlock [ "a", mempty, "\160b" ]
2423 , testGroup "field list"
2524 [ "general" =: unlines
2625 [ "para"
@@ -135,7 +134,7 @@ tests = [ "line block with blank line" =:
135134 codeBlock "block quotes\n\ncan go on for many lines" <>
136135 para "but must stop here")
137136 , "line block with 3 lines" =: "| a\n| b\n| c"
138− =?> para ("a" <> linebreak <> "b" <> linebreak <> "c")
137+ =?> lineBlock ["a", "b", "c"]
139138 , "quoted literal block using >" =: "::\n\n> quoted\n> block\n\nOrdinary paragraph"
140139 =?> codeBlock "> quoted\n> block" <> para "Ordinary paragraph"
141140 , "quoted literal block using | (not a line block)" =: "::\n\n| quoted\n| block\n\nOrdinary paragraph"
tests/markdown-reader-more.native+8−2
@@ -84,8 +84,14 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
8484,BlockQuote
8585 [Header 2 ("foobar",["baz"],[("key","val")]) [Str "Header",Space,Str "attributes",Space,Str "inside",Space,Str "block",Space,Str "quote"]]
8686,Header 2 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
87−,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
88−,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
87+,LineBlock
88+ [[Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be"]
89+ ,[Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,"]
90+ ,[Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,"]
91+ ,[Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
92+ ,[]
93+ ,[Str "Continuation",Space,Str "line"]
94+ ,[Str "\160\160and",Space,Str "another"]]
8995,Header 2 ("grid-tables",[],[]) [Str "Grid",Space,Str "Tables"]
9096,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
9197 [[Plain [Str "col",Space,Str "1"]]
tests/rst-reader.native+8−2
@@ -230,8 +230,14 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
230230,Para [Str "Another",Space,Str "paragraph"]
231231,Para [Str "A",Space,Str "third",Space,Str "paragraph"]
232232,Header 1 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
233−,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
234−,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
233+,LineBlock
234+ [[Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be"]
235+ ,[Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,"]
236+ ,[Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,"]
237+ ,[Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
238+ ,[]
239+ ,[Str "Continuation",Space,Str "line"]
240+ ,[Str "\160\160and",Space,Str "another"]]
235241,Header 1 ("simple-tables",[],[]) [Str "Simple",Space,Str "Tables"]
236242,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
237243 [[Plain [Str "col",Space,Str "1"]]