git.iko.soy/typeable/pandoc
on master help sign in
Modified str parser to capture apostrophes in smart mode.

This solves a problem stemming from the fact that a parser doesn't know what came *before* in the input stream. Previously pandoc would parse D'oh l'*aide* as containing a single quoted "oh l", when both `'`s should be apostrophes. (Issue #360.) There are two issues here. (a) It is obvious that the first `'` is not an open quote, becaues of the preceding `D`. This patch solves the problem. (b) It is obvious to us that the second `'` is not an open quote, because we see that *aide* is some text. But getting a good algorithm that has good performance is a bit tricky. You can't assume that `'` followed by `*` is always an apostrophe: *'this is quoted'* This patch does not fix (b).

commitdd96267626e6f52e49c912cfe90380de2df469e5 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 26 Dec 2011, 23:04 (15 years ago) parent765a777
1 file changed+9−2
src/Text/Pandoc/Readers/Markdown.hs+9−2
src/Text/Pandoc/Readers/Markdown.hs+9−2
@@ -44,7 +44,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockT
4444 isTextTag, isCommentTag )
4545import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
4646import Text.ParserCombinators.Parsec
47−import Control.Monad (when, liftM, guard)
47+import Control.Monad (when, liftM, guard, mzero)
4848import Text.HTML.TagSoup
4949import Text.HTML.TagSoup.Match (tagOpen)
5050
@@ -1087,8 +1087,15 @@ nonEndline = satisfy (/='\n')
10871087
10881088str :: GenParser Char ParserState Inline
10891089str = do
1090+ st <- getState
10901091 a <- alphaNum
1091− as <- many $ alphaNum <|> (try $ char '_' >>~ lookAhead alphaNum)
1092+ as <- many $ alphaNum
1093+ <|> (try $ char '_' >>~ lookAhead alphaNum)
1094+ <|> if stateStrict st
1095+ then mzero
1096+ else (try $ char '\'' >> lookAhead alphaNum >> return '\x2019')
1097+ -- for things like l'aide - would be better to return
1098+ -- an Apostrophe, but we can't in this context
10921099 let result = a:as
10931100 state <- getState
10941101 let spacesToNbr = map (\c -> if c == ' ' then '\160' else c)