Skip to content

Commit

Permalink
Org reader: Fix emphasis rules for smart parsing
Browse files Browse the repository at this point in the history
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 jgm#2513.
  • Loading branch information
tarleb committed Nov 13, 2015
1 parent a119ad8 commit 220f3d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Text/Pandoc/Readers/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

{- |
Module : Text.Pandoc.Readers.Org
Copyright : Copyright (C) 2014 Albert Krewinkel
Copyright : Copyright (C) 2014-2015 Albert Krewinkel
License : GNU GPL, version 2 or above
Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
Expand Down Expand Up @@ -1585,25 +1585,30 @@ smart :: OrgParser (F Inlines)
smart = do
getOption readerSmart >>= guard
doubleQuoted <|> singleQuoted <|>
choice (map (return <$>) [orgApostrophe, dash, ellipses])
where orgApostrophe =
choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
where
orgDash = dash <* updatePositions '-'
orgEllipses = ellipses <* updatePositions '.'
orgApostrophe =
(char '\'' <|> char '\8217') <* updateLastPreCharPos
<* updateLastForbiddenCharPos
*> return (B.str "\x2019")

singleQuoted :: OrgParser (F Inlines)
singleQuoted = try $ do
singleQuoteStart
updatePositions '\''
withQuoteContext InSingleQuote $
fmap B.singleQuoted . trimInlinesF . mconcat <$>
many1Till inline singleQuoteEnd
many1Till inline (singleQuoteEnd <* updatePositions '\'')

-- doubleQuoted will handle regular double-quoted sections, as well
-- as dialogues with an open double-quote without a close double-quote
-- in the same paragraph.
doubleQuoted :: OrgParser (F Inlines)
doubleQuoted = try $ do
doubleQuoteStart
updatePositions '"'
contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
(withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
(fmap B.doubleQuoted . trimInlinesF $ contents))
Expand Down
9 changes: 9 additions & 0 deletions tests/Tests/Readers/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ tests =
]
in codeBlockWith ( "", classes, params) "code body\n"
]

, testGroup "Smart punctuation"
[ test orgSmart "quote before ellipses"
("'...hi'"
Expand All @@ -1266,5 +1267,13 @@ tests =
, test orgSmart "Dashes are allowed at the borders of emphasis'"
("/foo---/" =?>
para (emph "foo—"))

, test orgSmart "Single quotes can be followed by emphasized text"
("Singles on the '/meat market/'" =?>
para ("Singles on the " <> (singleQuoted $ emph "meat market")))

, test orgSmart "Double quotes can be followed by emphasized text"
("Double income, no kids: \"/DINK/\"" =?>
para ("Double income, no kids: " <> (doubleQuoted $ emph "DINK")))
]
]

0 comments on commit 220f3d1

Please sign in to comment.