aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Silberman <[email protected]>2024-11-11 13:29:42 -0800
committerJohn MacFarlane <[email protected]>2024-11-11 16:00:47 -0800
commitfdef25eb6ed376826c3efade41f346340939831e (patch)
tree2ca0a2fb804ca49b59e3780f72861d3279a7f6c4
parentbe734d2543517a28bed7fef9b82d46dea56a61ea (diff)
Respect empty LineBlock lines in plain writer
The plain writer behaved as a markdown variant with Ext_line_blocks turned off, and so empty lines in a line block would get eliminated. This is surprising, since if there's anything where the intent can be preserved in plain text output it's empty lines. It's still a bit surprising to have nbsps in plain text output, as in the test, where the distinction doesn't really matter, but that'd be an orthogonal change.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs21
-rw-r--r--test/command/jabberwocky.md22
2 files changed, 36 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 62cbfba6c..4d669d36a 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -21,7 +21,7 @@ module Text.Pandoc.Writers.Markdown (
writeCommonMark,
writeMarkua,
writePlain) where
-import Control.Monad (foldM, zipWithM, MonadPlus(..), when)
+import Control.Monad (foldM, zipWithM, MonadPlus(..), when, liftM)
import Control.Monad.Reader ( asks, MonadReader(local) )
import Control.Monad.State.Strict ( gets, modify )
import Data.Default
@@ -447,12 +447,19 @@ blockToMarkdown' opts (Plain inlines) = do
return $ contents <> cr
blockToMarkdown' opts (Para inlines) =
(<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
-blockToMarkdown' opts (LineBlock lns) =
- if isEnabled Ext_line_blocks opts
- then do
- mdLines <- mapM (inlineListToMarkdown opts) lns
- return $ vcat (map (hang 2 (literal "| ")) mdLines) <> blankline
- else blockToMarkdown opts $ linesToPara lns
+blockToMarkdown' opts (LineBlock lns) = do
+ variant <- asks envVariant
+ case variant of
+ PlainText -> do
+ let emptyToBlank l = if isEmpty l then blankline else l
+ mdLines <- mapM (liftM emptyToBlank . inlineListToMarkdown opts) lns
+ return $ vcat mdLines <> blankline
+ _ ->
+ if isEnabled Ext_line_blocks opts
+ then do
+ mdLines <- mapM (inlineListToMarkdown opts) lns
+ return $ vcat (map (hang 2 (literal "| ")) mdLines) <> blankline
+ else blockToMarkdown opts $ linesToPara lns
blockToMarkdown' opts b@(RawBlock f str) = do
variant <- asks envVariant
let Format fmt = f
diff --git a/test/command/jabberwocky.md b/test/command/jabberwocky.md
new file mode 100644
index 000000000..442534f40
--- /dev/null
+++ b/test/command/jabberwocky.md
@@ -0,0 +1,22 @@
+```
+% pandoc -t plain -f markdown
+| 'Twas brillig, and the slithy toves
+| Did gyre and gimble in the wabe:
+| All mimsy were the borogoves,
+| And the mome raths outgrabe.
+|
+| "Beware the Jabberwock, my son!
+| The jaws that bite, the claws that catch!
+| Beware the Jubjub bird, and shun
+| The frumious Bandersnatch!"
+^D
+’Twas brillig, and the slithy toves
+      Did gyre and gimble in the wabe:
+All mimsy were the borogoves,
+      And the mome raths outgrabe.
+
+“Beware the Jabberwock, my son!
+      The jaws that bite, the claws that catch!
+Beware the Jubjub bird, and shun
+      The frumious Bandersnatch!”
+```