git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Simplified dash and ellipsis.

This originated with @dubiousjim's observation in #1419 that there was a typo in the definition of enDash. It returned an em dash character instead of an en dash. I thought about why this had not been noticed before, and realized that en dashes were just being parsed as regular symbols. That made me realize that, now that we no longer have dedicate EnDash, EmDash, and Ellipses inline elements, as we used to in pandoc, we no longer need to parse the unicode characters specially. This allowed a considerable simplification of the code. Partially resolves #1419.

commit47a5f04761d9921ee273e8264e26409c806a912d authorJohn MacFarlane <jgm@berkeley.edu> dateSat 12 Jul 2014, 22:59 (12 years ago) parent4676bfd
1 file changed+13−40
src/Text/Pandoc/Parsing.hs+13−40
src/Text/Pandoc/Parsing.hs+13−40
@@ -169,7 +169,7 @@ import Text.Pandoc.XML (fromEntities)
169169import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
170170import Text.Parsec
171171import Text.Parsec.Pos (newPos)
172−import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum, isDigit,
172+import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum,
173173 isHexDigit, isSpace )
174174import Data.List ( intercalate, transpose )
175175import Text.Pandoc.Shared
@@ -1124,48 +1124,21 @@ doubleQuoteEnd = void (charOrRef "\"\8221\148")
11241124
11251125ellipses :: Stream s m Char
11261126 => ParserT s st m Inlines
1127−ellipses = do
1128− try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
1129− return (B.str "\8230")
1127+ellipses = try (string "..." >> return (B.str "\8230"))
11301128
1131−dash :: Stream s m Char => ParserT s ParserState m Inlines
1132−dash = do
1129+dash :: (HasReaderOptions st, Stream s m Char)
1130+ => ParserT s st m Inlines
1131+dash = try $ do
11331132 oldDashes <- getOption readerOldDashes
11341133 if oldDashes
1135− then emDashOld <|> enDashOld
1136− else B.str <$> (hyphenDash <|> emDash <|> enDash)
1137−
1138−-- Two hyphens = en-dash, three = em-dash
1139−hyphenDash :: Stream s m Char
1140− => ParserT s st m String
1141−hyphenDash = do
1142− try $ string "--"
1143− option "\8211" (char '-' >> return "\8212")
1144−
1145−emDash :: Stream s m Char
1146− => ParserT s st m String
1147−emDash = do
1148− try (charOrRef "\8212\151")
1149− return "\8212"
1150−
1151−enDash :: Stream s m Char
1152− => ParserT s st m String
1153−enDash = do
1154− try (charOrRef "\8212\151")
1155− return "\8211"
1156−
1157−enDashOld :: Stream s m Char
1158− => ParserT s st m Inlines
1159−enDashOld = do
1160− try (charOrRef "\8211\150") <|>
1161− try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
1162− return (B.str "\8211")
1163−
1164−emDashOld :: Stream s m Char
1165− => ParserT s st m Inlines
1166−emDashOld = do
1167− try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
1168− return (B.str "\8212")
1134+ then do
1135+ char '-'
1136+ (char '-' >> return (B.str "\8212"))
1137+ <|> (lookAhead digit >> return (B.str "\8211"))
1138+ else do
1139+ string "--"
1140+ (char '-' >> return (B.str "\8212"))
1141+ <|> return (B.str "\8211")
11691142
11701143-- This is used to prevent exponential blowups for things like:
11711144-- a**a*a**a*a**a*a**a*a**a*a**a*a**