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
This commit is contained in:
parent
0515c44859
commit
b9b2586ed3
2 changed files with 17 additions and 4 deletions
|
@ -17,7 +17,7 @@ Org-Mode: <http://orgmode.org>
|
|||
-}
|
||||
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.
|
||||
|
|
10
test/command/7132.md
Normal file
10
test/command/7132.md
Normal file
|
@ -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)
|
||||
```
|
Loading…
Reference in a new issue