git.iko.soy/typeable/pandoc
on master help sign in
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

commitb9b2586ed3e9aac9c5ba86127fbf984fb3149844 authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 9 Mar 2021, 18:01 (6 years ago) parent0515c44
2 files changed+17−4
src/Text/Pandoc/Writers/Org.hs+7−4 test/command/7132.md+10
src/Text/Pandoc/Writers/Org.hs+7−4
@@ -17,7 +17,7 @@ Org-Mode: <http://orgmode.org>
1717-}
1818module Text.Pandoc.Writers.Org (writeOrg) where
1919import Control.Monad.State.Strict
20−import Data.Char (isAlphaNum)
20+import Data.Char (isAlphaNum, isDigit)
2121import Data.List (intersect, intersperse, partition, transpose)
2222import Data.Text (Text)
2323import qualified Data.Text as T
@@ -347,16 +347,19 @@ inlineListToOrg :: PandocMonad m
347347 => [Inline]
348348 -> Org m (Doc Text)
349349inlineListToOrg lst = hcat <$> mapM inlineToOrg (fixMarkers lst)
350− where fixMarkers [] = [] -- prevent note refs and list markers from wrapping, see #4171
350+ where -- Prevent note refs and list markers from wrapping, see #4171
351+ -- and #7132.
352+ fixMarkers [] = []
351353 fixMarkers (Space : x : rest) | shouldFix x =
352354 Str " " : x : fixMarkers rest
353355 fixMarkers (SoftBreak : x : rest) | shouldFix x =
354356 Str " " : x : fixMarkers rest
355357 fixMarkers (x : rest) = x : fixMarkers rest
356358
357− shouldFix Note{} = True -- Prevent footnotes
359+ shouldFix Note{} = True -- Prevent footnotes
358360 shouldFix (Str "-") = True -- Prevent bullet list items
359− -- TODO: prevent ordered list items
361+ shouldFix (Str x) -- Prevent ordered list items
362+ | Just (cs, c) <- T.unsnoc x = T.all isDigit cs && c == '.' || c == ')'
360363 shouldFix _ = False
361364
362365-- | Convert Pandoc inline element to Org.
test/command/7132.mdnew file+10
@@ -0,0 +1,10 @@
1+```
2+% pandoc -f markdown -t org --columns=72
3+- This line has exactly the wrong number of characters before the number 5.
4+- Long line ending with a number (this time it is in parentheses and a 23)
5+^D
6+- This line has exactly the wrong number of characters before the
7+ number 5.
8+- Long line ending with a number (this time it is in parentheses and
9+ a 23)
10+```