git.iko.soy/typeable/pandoc
on master help sign in
Org reader: fix rules for emphasis recognition

Things like `/hello,/` or `/hi'/` were falsy recognized as emphasised strings. This is wrong, as `,` and `'` are forbidden border chars and may not occur on the inner border of emphasized text. This patch enables the reader to matches the reference implementation in that it reads the above strings as plain text.

commitd571bec454e9f0822c2c71eeee2f8bfc6eb34c3c authorAlbert Krewinkel <albert@zeitkraut.de> dateSat 18 Oct 2014, 10:38 (12 years ago) parent8b60d43
2 files changed+13−5
src/Text/Pandoc/Readers/Org.hs+5−5 tests/Tests/Readers/Org.hs+8
src/Text/Pandoc/Readers/Org.hs+5−5
@@ -927,7 +927,7 @@ parseInlines = trimInlinesF . mconcat <$> many1 inline
927927
928928-- treat these as potentially non-text when parsing inline:
929929specialChars :: [Char]
930−specialChars = "\"$'()*+-./:<=>[\\]^_{|}~"
930+specialChars = "\"$'()*+-,./:<=>[\\]^_{|}~"
931931
932932
933933whitespace :: OrgParser (F Inlines)
@@ -1205,10 +1205,10 @@ displayMath = return . B.displayMath <$> choice [ rawMathBetween "\\[" "\\]"
12051205 ]
12061206symbol :: OrgParser (F Inlines)
12071207symbol = return . B.str . (: "") <$> (oneOf specialChars >>= updatePositions)
1208− where updatePositions c
1209− | c `elem` emphasisPreChars = c <$ updateLastPreCharPos
1210− | c `elem` emphasisForbiddenBorderChars = c <$ updateLastForbiddenCharPos
1211− | otherwise = return c
1208+ where updatePositions c = do
1209+ when (c `elem` emphasisPreChars) updateLastPreCharPos
1210+ when (c `elem` emphasisForbiddenBorderChars) updateLastForbiddenCharPos
1211+ return c
12121212
12131213emphasisBetween :: Char
12141214 -> OrgParser (F Inlines)
tests/Tests/Readers/Org.hs+8
@@ -126,6 +126,14 @@ tests =
126126 , (emph "b") <> "."
127127 ])
128128
129+ , "Quotes are forbidden border chars" =:
130+ "/'nope/ *nope\"*" =?>
131+ para ("/'nope/" <> space <> "*nope\"*")
132+
133+ , "Commata are forbidden border chars" =:
134+ "/nada,/" =?>
135+ para "/nada,/"
136+
129137 , "Markup should work properly after a blank line" =:
130138 unlines ["foo", "", "/bar/"] =?>
131139 (para $ text "foo") <> (para $ emph $ text "bar")