Merge pull request #2525 from tarleb/org-smart-fixes
Org reader: Fix emphasis rules for smart parsing
This commit is contained in:
commit
028a605bf8
2 changed files with 18 additions and 4 deletions
|
@ -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>
|
||||
|
@ -1585,8 +1585,11 @@ 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")
|
||||
|
@ -1594,9 +1597,10 @@ smart = do
|
|||
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
|
||||
|
@ -1604,6 +1608,7 @@ singleQuoted = try $ do
|
|||
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))
|
||||
|
|
|
@ -1246,6 +1246,7 @@ tests =
|
|||
]
|
||||
in codeBlockWith ( "", classes, params) "code body\n"
|
||||
]
|
||||
|
||||
, testGroup "Smart punctuation"
|
||||
[ test orgSmart "quote before ellipses"
|
||||
("'...hi'"
|
||||
|
@ -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")))
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue