git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix emphasis rules for smart parsing
220f3d1Albert Krewinkel
src/Text/Pandoc/Readers/Org.hs+9−4
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
21
22{- |
22{- |
23 Module : Text.Pandoc.Readers.Org
23 Module : Text.Pandoc.Readers.Org
24− Copyright : Copyright (C) 2014 Albert Krewinkel
24+ Copyright : Copyright (C) 2014-2015 Albert Krewinkel
25 License : GNU GPL, version 2 or above
25 License : GNU GPL, version 2 or above
26
26
27 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
27 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
@@ -1585,8 +1585,11 @@ smart :: OrgParser (F Inlines)
1585smart = do
1585smart = do
1586 getOption readerSmart >>= guard
1586 getOption readerSmart >>= guard
1587 doubleQuoted <|> singleQuoted <|>
1587 doubleQuoted <|> singleQuoted <|>
1588− choice (map (return <$>) [orgApostrophe, dash, ellipses])
1588+ choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
1589+ where
1590+ orgDash = dash <* updatePositions '-'
1591+ orgEllipses = ellipses <* updatePositions '.'
1589− where orgApostrophe =
1592+ orgApostrophe =
1590 (char '\'' <|> char '\8217') <* updateLastPreCharPos
1593 (char '\'' <|> char '\8217') <* updateLastPreCharPos
1591 <* updateLastForbiddenCharPos
1594 <* updateLastForbiddenCharPos
1592 *> return (B.str "\x2019")
1595 *> return (B.str "\x2019")
@@ -1594,9 +1597,10 @@ smart = do
1594singleQuoted :: OrgParser (F Inlines)
1597singleQuoted :: OrgParser (F Inlines)
1595singleQuoted = try $ do
1598singleQuoted = try $ do
1596 singleQuoteStart
1599 singleQuoteStart
1600+ updatePositions '\''
1597 withQuoteContext InSingleQuote $
1601 withQuoteContext InSingleQuote $
1598 fmap B.singleQuoted . trimInlinesF . mconcat <$>
1602 fmap B.singleQuoted . trimInlinesF . mconcat <$>
1599− many1Till inline singleQuoteEnd
1603+ many1Till inline (singleQuoteEnd <* updatePositions '\'')
1600
1604
1601-- doubleQuoted will handle regular double-quoted sections, as well
1605-- doubleQuoted will handle regular double-quoted sections, as well
1602-- as dialogues with an open double-quote without a close double-quote
1606-- as dialogues with an open double-quote without a close double-quote
@@ -1604,6 +1608,7 @@ singleQuoted = try $ do
1604doubleQuoted :: OrgParser (F Inlines)
1608doubleQuoted :: OrgParser (F Inlines)
1605doubleQuoted = try $ do
1609doubleQuoted = try $ do
1606 doubleQuoteStart
1610 doubleQuoteStart
1611+ updatePositions '"'
1607 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
1612 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
1608 (withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
1613 (withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
1609 (fmap B.doubleQuoted . trimInlinesF $ contents))
1614 (fmap B.doubleQuoted . trimInlinesF $ contents))
tests/Tests/Readers/Org.hs+9
@@ -1246,6 +1246,7 @@ tests =
1246 ]
1246 ]
1247 in codeBlockWith ( "", classes, params) "code body\n"
1247 in codeBlockWith ( "", classes, params) "code body\n"
1248 ]
1248 ]
1249+
1249 , testGroup "Smart punctuation"
1250 , testGroup "Smart punctuation"
1250 [ test orgSmart "quote before ellipses"
1251 [ test orgSmart "quote before ellipses"
1251 ("'...hi'"
1252 ("'...hi'"
@@ -1266,5 +1267,13 @@ tests =
1266 , test orgSmart "Dashes are allowed at the borders of emphasis'"
1267 , test orgSmart "Dashes are allowed at the borders of emphasis'"
1267 ("/foo---/" =?>
1268 ("/foo---/" =?>
1268 para (emph "foo—"))
1269 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")))
1269 ]
1278 ]
1270 ]
1279 ]