git.iko.soy/typeable/pandoc
on master help sign in
Org writer: prevent unintended creation of ordered list items
b9b2586Albert Krewinkel
src/Text/Pandoc/Writers/Org.hs+7−4
@@ -17,7 +17,7 @@ Org-Mode: <http://orgmode.org>
17-}
17-}
18module Text.Pandoc.Writers.Org (writeOrg) where
18module Text.Pandoc.Writers.Org (writeOrg) where
19import Control.Monad.State.Strict
19import Control.Monad.State.Strict
20−import Data.Char (isAlphaNum)
20+import Data.Char (isAlphaNum, isDigit)
21import Data.List (intersect, intersperse, partition, transpose)
21import Data.List (intersect, intersperse, partition, transpose)
22import Data.Text (Text)
22import Data.Text (Text)
23import qualified Data.Text as T
23import qualified Data.Text as T
@@ -347,16 +347,19 @@ inlineListToOrg :: PandocMonad m
347 => [Inline]
347 => [Inline]
348 -> Org m (Doc Text)
348 -> Org m (Doc Text)
349inlineListToOrg lst = hcat <$> mapM inlineToOrg (fixMarkers lst)
349inlineListToOrg 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 [] = []
351 fixMarkers (Space : x : rest) | shouldFix x =
353 fixMarkers (Space : x : rest) | shouldFix x =
352 Str " " : x : fixMarkers rest
354 Str " " : x : fixMarkers rest
353 fixMarkers (SoftBreak : x : rest) | shouldFix x =
355 fixMarkers (SoftBreak : x : rest) | shouldFix x =
354 Str " " : x : fixMarkers rest
356 Str " " : x : fixMarkers rest
355 fixMarkers (x : rest) = x : fixMarkers rest
357 fixMarkers (x : rest) = x : fixMarkers rest
356
358
357− shouldFix Note{} = True -- Prevent footnotes
359+ shouldFix Note{} = True -- Prevent footnotes
358 shouldFix (Str "-") = True -- Prevent bullet list items
360 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 == ')'
360 shouldFix _ = False
363 shouldFix _ = False
361
364
362-- | Convert Pandoc inline element to Org.
365-- | 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+```