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.
This commit is contained in:
parent
8b60d430f2
commit
d571bec454
2 changed files with 13 additions and 5 deletions
|
@ -927,7 +927,7 @@ parseInlines = trimInlinesF . mconcat <$> many1 inline
|
||||||
|
|
||||||
-- treat these as potentially non-text when parsing inline:
|
-- treat these as potentially non-text when parsing inline:
|
||||||
specialChars :: [Char]
|
specialChars :: [Char]
|
||||||
specialChars = "\"$'()*+-./:<=>[\\]^_{|}~"
|
specialChars = "\"$'()*+-,./:<=>[\\]^_{|}~"
|
||||||
|
|
||||||
|
|
||||||
whitespace :: OrgParser (F Inlines)
|
whitespace :: OrgParser (F Inlines)
|
||||||
|
@ -1205,10 +1205,10 @@ displayMath = return . B.displayMath <$> choice [ rawMathBetween "\\[" "\\]"
|
||||||
]
|
]
|
||||||
symbol :: OrgParser (F Inlines)
|
symbol :: OrgParser (F Inlines)
|
||||||
symbol = return . B.str . (: "") <$> (oneOf specialChars >>= updatePositions)
|
symbol = return . B.str . (: "") <$> (oneOf specialChars >>= updatePositions)
|
||||||
where updatePositions c
|
where updatePositions c = do
|
||||||
| c `elem` emphasisPreChars = c <$ updateLastPreCharPos
|
when (c `elem` emphasisPreChars) updateLastPreCharPos
|
||||||
| c `elem` emphasisForbiddenBorderChars = c <$ updateLastForbiddenCharPos
|
when (c `elem` emphasisForbiddenBorderChars) updateLastForbiddenCharPos
|
||||||
| otherwise = return c
|
return c
|
||||||
|
|
||||||
emphasisBetween :: Char
|
emphasisBetween :: Char
|
||||||
-> OrgParser (F Inlines)
|
-> OrgParser (F Inlines)
|
||||||
|
|
|
@ -126,6 +126,14 @@ tests =
|
||||||
, (emph "b") <> "."
|
, (emph "b") <> "."
|
||||||
])
|
])
|
||||||
|
|
||||||
|
, "Quotes are forbidden border chars" =:
|
||||||
|
"/'nope/ *nope\"*" =?>
|
||||||
|
para ("/'nope/" <> space <> "*nope\"*")
|
||||||
|
|
||||||
|
, "Commata are forbidden border chars" =:
|
||||||
|
"/nada,/" =?>
|
||||||
|
para "/nada,/"
|
||||||
|
|
||||||
, "Markup should work properly after a blank line" =:
|
, "Markup should work properly after a blank line" =:
|
||||||
unlines ["foo", "", "/bar/"] =?>
|
unlines ["foo", "", "/bar/"] =?>
|
||||||
(para $ text "foo") <> (para $ emph $ text "bar")
|
(para $ text "foo") <> (para $ emph $ text "bar")
|
||||||
|
|
Loading…
Reference in a new issue