From b9b2586ed3e9aac9c5ba86127fbf984fb3149844 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 9 Mar 2021 18:01:08 +0100 Subject: Org writer: prevent unintended creation of ordered list items Adjust line wrapping if default wrapping would cause a line to be read as an ordered list item. Fixes #7132 --- src/Text/Pandoc/Writers/Org.hs | 11 +++++++---- test/command/7132.md | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/command/7132.md diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index 8dfc2749c..1b525831e 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -17,7 +17,7 @@ Org-Mode: -} module Text.Pandoc.Writers.Org (writeOrg) where import Control.Monad.State.Strict -import Data.Char (isAlphaNum) +import Data.Char (isAlphaNum, isDigit) import Data.List (intersect, intersperse, partition, transpose) import Data.Text (Text) import qualified Data.Text as T @@ -347,16 +347,19 @@ inlineListToOrg :: PandocMonad m => [Inline] -> Org m (Doc Text) inlineListToOrg lst = hcat <$> mapM inlineToOrg (fixMarkers lst) - where fixMarkers [] = [] -- prevent note refs and list markers from wrapping, see #4171 + where -- Prevent note refs and list markers from wrapping, see #4171 + -- and #7132. + fixMarkers [] = [] fixMarkers (Space : x : rest) | shouldFix x = Str " " : x : fixMarkers rest fixMarkers (SoftBreak : x : rest) | shouldFix x = Str " " : x : fixMarkers rest fixMarkers (x : rest) = x : fixMarkers rest - shouldFix Note{} = True -- Prevent footnotes + shouldFix Note{} = True -- Prevent footnotes shouldFix (Str "-") = True -- Prevent bullet list items - -- TODO: prevent ordered list items + shouldFix (Str x) -- Prevent ordered list items + | Just (cs, c) <- T.unsnoc x = T.all isDigit cs && c == '.' || c == ')' shouldFix _ = False -- | Convert Pandoc inline element to Org. diff --git a/test/command/7132.md b/test/command/7132.md new file mode 100644 index 000000000..30d4c0b3b --- /dev/null +++ b/test/command/7132.md @@ -0,0 +1,10 @@ +``` +% pandoc -f markdown -t org --columns=72 +- This line has exactly the wrong number of characters before the number 5. +- Long line ending with a number (this time it is in parentheses and a 23) +^D +- This line has exactly the wrong number of characters before the + number 5. +- Long line ending with a number (this time it is in parentheses and + a 23) +``` -- cgit v1.2.3