git.iko.soy/typeable/pandoc
on master help sign in
Smart punctuation: recognize entities.

Now “Hi” gets parsed as a Quoted DoubleQuote inline.

commit33ba35da9fd584a17b6b1011daa76a8232799c18 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Dec 2010, 20:44 (16 years ago) parent3a5fcee
2 files changed+23−9
src/Text/Pandoc/Parsing.hs+22−8 src/Text/Pandoc/Readers/Markdown.hs+1−1
src/Text/Pandoc/Parsing.hs+22−8
@@ -730,10 +730,16 @@ failIfInQuoteContext context = do
730730 then fail "already inside quotes"
731731 else return ()
732732
733+charOrRef :: [Char] -> GenParser Char st Char
734+charOrRef cs =
735+ oneOf cs <|> try (do c <- characterReference
736+ guard (c `elem` cs)
737+ return c)
738+
733739singleQuoteStart :: GenParser Char ParserState ()
734740singleQuoteStart = do
735741 failIfInQuoteContext InSingleQuote
736− try $ do oneOf "'\8216"
742+ try $ do charOrRef "'\8216"
737743 notFollowedBy (oneOf ")!],.;:-? \t\n")
738744 notFollowedBy (try (oneOfStrings ["s","t","m","ve","ll","re"] >>
739745 satisfy (not . isAlphaNum)))
@@ -742,28 +748,36 @@ singleQuoteStart = do
742748
743749singleQuoteEnd :: GenParser Char st ()
744750singleQuoteEnd = try $ do
745− oneOf "'\8217"
751+ charOrRef "'\8217"
746752 notFollowedBy alphaNum
747753
748754doubleQuoteStart :: GenParser Char ParserState ()
749755doubleQuoteStart = do
750756 failIfInQuoteContext InDoubleQuote
751− try $ do oneOf "\"\8220"
757+ try $ do charOrRef "\"\8220"
752758 notFollowedBy (oneOf " \t\n")
753759
754760doubleQuoteEnd :: GenParser Char st ()
755−doubleQuoteEnd = oneOf "\"\8221" >> return ()
761+doubleQuoteEnd = do
762+ charOrRef "\"\8221"
763+ return ()
756764
757765ellipses :: GenParser Char st Inline
758−ellipses = try $ string "..." >> return Ellipses
766+ellipses = do
767+ try (charOrRef "…") <|> try (string "..." >> return '…')
768+ return Ellipses
759769
760770dash :: GenParser Char st Inline
761771dash = enDash <|> emDash
762772
763773enDash :: GenParser Char st Inline
764−enDash = try $ char '-' >> notFollowedBy (noneOf "0123456789") >> return EnDash
774+enDash = do
775+ try (charOrRef "–") <|>
776+ try (char '-' >> notFollowedBy (noneOf "0123456789") >> return '–')
777+ return EnDash
765778
766779emDash :: GenParser Char st Inline
767−emDash = oneOfStrings ["---", "--"] >> return EmDash
768−
780+emDash = do
781+ try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
782+ return EmDash
769783
src/Text/Pandoc/Readers/Markdown.hs+1−1
@@ -900,7 +900,6 @@ inlineParsers = [ str
900900 , whitespace
901901 , endline
902902 , code
903− , charRef
904903 , (fourOrMore '*' <|> fourOrMore '_')
905904 , strong
906905 , emph
@@ -919,6 +918,7 @@ inlineParsers = [ str
919918 , escapedChar
920919 , exampleRef
921920 , smartPunctuation inline
921+ , charRef
922922 , symbol
923923 , ltSign ]
924924