git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3065 from tarleb/org-verse-indent
13424a2John MacFarlane
src/Text/Pandoc/Readers/Org/Blocks.hs+10−1
@@ -422,7 +422,16 @@ verseBlock blockType = try $ do
422 ignHeaders
422 ignHeaders
423 content <- rawBlockContent blockType
423 content <- rawBlockContent blockType
424 fmap B.para . mconcat . intersperse (pure B.linebreak)
424 fmap B.para . mconcat . intersperse (pure B.linebreak)
425+ <$> mapM parseVerseLine (lines content)
426+ where
427+ -- replace initial spaces with nonbreaking spaces to preserve
428+ -- indentation, parse the rest as normal inline
429+ parseVerseLine :: String -> OrgParser (F Inlines)
430+ parseVerseLine cs = do
431+ let (initialSpaces, indentedLine) = span isSpace cs
432+ let nbspIndent = B.str $ map (const '\160') initialSpaces
425− <$> mapM (parseFromString inlines) (map (++ "\n") . lines $ content)
433+ line <- parseFromString inlines (indentedLine ++ "\n")
434+ return (pure nbspIndent <> line)
426
435
427-- | Read a code block and the associated results block if present. Which of
436-- | Read a code block and the associated results block if present. Which of
428-- boths blocks is included in the output is determined using the "exports"
437-- boths blocks is included in the output is determined using the "exports"
tests/Tests/Readers/Org.hs+8
@@ -1440,6 +1440,14 @@ tests =
1440 ] =?>
1440 ] =?>
1441 para ("foo" <> linebreak <> linebreak <> "bar")
1441 para ("foo" <> linebreak <> linebreak <> "bar")
1442
1442
1443+ , "Verse block with varying indentation" =:
1444+ unlines [ "#+BEGIN_VERSE"
1445+ , " hello darkness"
1446+ , "my old friend"
1447+ , "#+END_VERSE"
1448+ ] =?>
1449+ para ("\160\160hello darkness" <> linebreak <> "my old friend")
1450+
1443 , "Raw block LaTeX" =:
1451 , "Raw block LaTeX" =:
1444 unlines [ "#+BEGIN_LaTeX"
1452 unlines [ "#+BEGIN_LaTeX"
1445 , "The category $\\cat{Set}$ is adhesive."
1453 , "The category $\\cat{Set}$ is adhesive."