git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix emphasis rules for smart parsing

Smart quotes, ellipses, and dashes should behave like normal quotes, single dashes, and dots with respect to text markup parsing. The parser state was not updated properly in all cases, which has been fixed. Thanks to @conklech for reporting this issue. This fixes #2513.

commit220f3d12b804a8baa188e9c7174707d3cb0316e1 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 13 Nov 2015, 20:32 (11 years ago) parenta119ad8
2 files changed+18−4
src/Text/Pandoc/Readers/Org.hs+9−4 tests/Tests/Readers/Org.hs+9
src/Text/Pandoc/Readers/Org.hs+9−4
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
2222{- |
2323 Module : Text.Pandoc.Readers.Org
24− Copyright : Copyright (C) 2014 Albert Krewinkel
24+ Copyright : Copyright (C) 2014-2015 Albert Krewinkel
2525 License : GNU GPL, version 2 or above
2626
2727 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
@@ -1585,8 +1585,11 @@ smart :: OrgParser (F Inlines)
15851585smart = do
15861586 getOption readerSmart >>= guard
15871587 doubleQuoted <|> singleQuoted <|>
1588− choice (map (return <$>) [orgApostrophe, dash, ellipses])
1589− where orgApostrophe =
1588+ choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
1589+ where
1590+ orgDash = dash <* updatePositions '-'
1591+ orgEllipses = ellipses <* updatePositions '.'
1592+ orgApostrophe =
15901593 (char '\'' <|> char '\8217') <* updateLastPreCharPos
15911594 <* updateLastForbiddenCharPos
15921595 *> return (B.str "\x2019")
@@ -1594,9 +1597,10 @@ smart = do
15941597singleQuoted :: OrgParser (F Inlines)
15951598singleQuoted = try $ do
15961599 singleQuoteStart
1600+ updatePositions '\''
15971601 withQuoteContext InSingleQuote $
15981602 fmap B.singleQuoted . trimInlinesF . mconcat <$>
1599− many1Till inline singleQuoteEnd
1603+ many1Till inline (singleQuoteEnd <* updatePositions '\'')
16001604
16011605-- doubleQuoted will handle regular double-quoted sections, as well
16021606-- as dialogues with an open double-quote without a close double-quote
@@ -1604,6 +1608,7 @@ singleQuoted = try $ do
16041608doubleQuoted :: OrgParser (F Inlines)
16051609doubleQuoted = try $ do
16061610 doubleQuoteStart
1611+ updatePositions '"'
16071612 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
16081613 (withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
16091614 (fmap B.doubleQuoted . trimInlinesF $ contents))
tests/Tests/Readers/Org.hs+9
@@ -1246,6 +1246,7 @@ tests =
12461246 ]
12471247 in codeBlockWith ( "", classes, params) "code body\n"
12481248 ]
1249+
12491250 , testGroup "Smart punctuation"
12501251 [ test orgSmart "quote before ellipses"
12511252 ("'...hi'"
@@ -1266,5 +1267,13 @@ tests =
12661267 , test orgSmart "Dashes are allowed at the borders of emphasis'"
12671268 ("/foo---/" =?>
12681269 para (emph "foo—"))
1270+
1271+ , test orgSmart "Single quotes can be followed by emphasized text"
1272+ ("Singles on the '/meat market/'" =?>
1273+ para ("Singles on the " <> (singleQuoted $ emph "meat market")))
1274+
1275+ , test orgSmart "Double quotes can be followed by emphasized text"
1276+ ("Double income, no kids: \"/DINK/\"" =?>
1277+ para ("Double income, no kids: " <> (doubleQuoted $ emph "DINK")))
12691278 ]
12701279 ]