git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2525 from tarleb/org-smart-fixes

Org reader: Fix emphasis rules for smart parsing

commit028a605bf80fbdd54ed22cab56b2ce88cde2d89c authorJohn MacFarlane <jgm@berkeley.edu> dateFri 13 Nov 2015, 12:27 (11 years ago) parent03ea420220f3d1
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 ]