git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Simplified dash and ellipsis.
47a5f04John MacFarlane
src/Text/Pandoc/Parsing.hs+13−40
@@ -169,7 +169,7 @@ import Text.Pandoc.XML (fromEntities)
169import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
169import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
170import Text.Parsec
170import Text.Parsec
171import Text.Parsec.Pos (newPos)
171import 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,
173 isHexDigit, isSpace )
173 isHexDigit, isSpace )
174import Data.List ( intercalate, transpose )
174import Data.List ( intercalate, transpose )
175import Text.Pandoc.Shared
175import Text.Pandoc.Shared
@@ -1124,48 +1124,21 @@ doubleQuoteEnd = void (charOrRef "\"\8221\148")
1124
1124
1125ellipses :: Stream s m Char
1125ellipses :: Stream s m Char
1126 => ParserT s st m Inlines
1126 => ParserT s st m Inlines
1127−ellipses = do
1128− try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
1127+ellipses = try (string "..." >> return (B.str "\8230"))
1129− return (B.str "\8230")
1130
1128
1129+dash :: (HasReaderOptions st, Stream s m Char)
1131−dash :: Stream s m Char => ParserT s ParserState m Inlines
1130+ => ParserT s st m Inlines
1132−dash = do
1131+dash = try $ do
1133 oldDashes <- getOption readerOldDashes
1132 oldDashes <- getOption readerOldDashes
1134 if oldDashes
1133 if oldDashes
1135− then emDashOld <|> enDashOld
1134+ then do
1136− else B.str <$> (hyphenDash <|> emDash <|> enDash)
1135+ char '-'
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")
1136+ (char '-' >> return (B.str "\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")
1137+ <|> (lookAhead digit >> return (B.str "\8211"))
1163−
1138+ else do
1164−emDashOld :: Stream s m Char
1139+ string "--"
1165− => ParserT s st m Inlines
1140+ (char '-' >> return (B.str "\8212"))
1166−emDashOld = do
1167− try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
1168− return (B.str "\8212")
1141+ <|> return (B.str "\8211")
1169
1142
1170-- This is used to prevent exponential blowups for things like:
1143-- This is used to prevent exponential blowups for things like:
1171-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1144-- a**a*a**a*a**a*a**a*a**a*a**a*a**