From fa01764a0ea1373ecb9f0afffec391e3bc87d07a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 27 May 2024 14:31:39 -0700 Subject: [PATCH] CSV reader: turn line breaks into LineBreaks not SoftBreaks. Closes #9797. --- src/Text/Pandoc/Readers/CSV.hs | 4 +++- test/command/9797.md | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/command/9797.md diff --git a/src/Text/Pandoc/Readers/CSV.hs b/src/Text/Pandoc/Readers/CSV.hs index 3d2de11a5..294e20add 100644 --- a/src/Text/Pandoc/Readers/CSV.hs +++ b/src/Text/Pandoc/Readers/CSV.hs @@ -25,6 +25,7 @@ import Text.Pandoc.Sources (ToSources(..), sourcesToText) import Text.Pandoc.Options (ReaderOptions) import Control.Monad.Except (throwError) import Data.Text (Text) +import Data.List (intersperse) import Text.Pandoc.Parsing (fromParsecError) readCSV :: (PandocMonad m, ToSources a) @@ -60,7 +61,8 @@ readCSVWith csvopts txt = do (TableFoot nullAttr []) where capt = B.emptyCaption numcols = length r - toplain = B.simpleCell . B.plain . B.text . T.strip + toplain = B.simpleCell . B.plain . mconcat . + intersperse B.linebreak . map B.text . T.lines toRow = Row nullAttr . map toplain toHeaderRow l = [toRow l | not (null l)] hdrs = toHeaderRow r diff --git a/test/command/9797.md b/test/command/9797.md new file mode 100644 index 000000000..b3c562232 --- /dev/null +++ b/test/command/9797.md @@ -0,0 +1,39 @@ +``` +% pandoc -t native -f csv +"one_line_break: +four_line_breaks: + + + +last_line" +^D +[ Table + ( "" , [] , [] ) + (Caption Nothing []) + [ ( AlignDefault , ColWidthDefault ) ] + (TableHead + ( "" , [] , [] ) + [ Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 1) + [ Plain + [ Str "one_line_break:" + , LineBreak + , Str "four_line_breaks:" + , LineBreak + , LineBreak + , LineBreak + , LineBreak + , Str "last_line" + ] + ] + ] + ]) + [ TableBody ( "" , [] , [] ) (RowHeadColumns 0) [] [] ] + (TableFoot ( "" , [] , [] ) []) +] +```