git.iko.soy/typeable/pandoc
on master help sign in
Parse line-oriented markup as LineBlock

Markup-features focusing on lines as distinctive part of the markup are read into `LineBlock` elements. This currently means line blocks in reStructuredText and Markdown (the latter only if the `line_block` extension is enabled), the `linegroup`/`line` combination from the Docbook 5.1 working draft, and Org-mode `VERSE` blocks.

commitc9460e7013d395f77f75a4eb6bde933ffc34b6b6 authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 13 Oct 2016, 08:46 (10 years ago) parent22cb9e3
8 files changed+34−26
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 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
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
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"]]