git.iko.soy/typeable/pandoc
on master help sign in
Implemented Ext_tex_math_single_backslash, Ext_tex_math_double_backslash.
9591fc9John MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+28−20
@@ -1169,34 +1169,42 @@ code = try $ do
1169 optional whitespace >> attributes)
1169 optional whitespace >> attributes)
1170 return $ return $ B.codeWith attr $ removeLeadingTrailingSpace $ concat result
1170 return $ return $ B.codeWith attr $ removeLeadingTrailingSpace $ concat result
1171
1171
1172−mathWord :: Parser [Char] st String
1173−mathWord = liftM concat $ many1 mathChunk
1174−
1175−mathChunk :: Parser [Char] st String
1176−mathChunk = do char '\\'
1177− c <- anyChar
1178− return ['\\',c]
1179− <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1180−
1181math :: Parser [Char] ParserState (F Inlines)
1172math :: Parser [Char] ParserState (F Inlines)
1182math = (return . B.displayMath <$> (mathDisplay >>= applyMacros'))
1173math = (return . B.displayMath <$> (mathDisplay >>= applyMacros'))
1183 <|> (return . B.math <$> (mathInline >>= applyMacros'))
1174 <|> (return . B.math <$> (mathInline >>= applyMacros'))
1184
1175
1185mathDisplay :: Parser [Char] ParserState String
1176mathDisplay :: Parser [Char] ParserState String
1186−mathDisplay = try $ do
1177+mathDisplay =
1187− guardEnabled Ext_tex_math_dollars
1178+ (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
1188− string "$$"
1179+ <|> (guardEnabled Ext_tex_math_single_backslash >>
1180+ mathDisplayWith "\\[" "\\]")
1181+ <|> (guardEnabled Ext_tex_math_double_backslash >>
1182+ mathDisplayWith "\\\\[" "\\\\]")
1183+
1184+mathDisplayWith :: String -> String -> Parser [Char] ParserState String
1185+mathDisplayWith op cl = try $ do
1186+ string op
1189− many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1187+ many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
1190
1188
1191mathInline :: Parser [Char] ParserState String
1189mathInline :: Parser [Char] ParserState String
1192−mathInline = try $ do
1190+mathInline =
1193− guardEnabled Ext_tex_math_dollars
1191+ (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
1194− char '$'
1192+ <|> (guardEnabled Ext_tex_math_single_backslash >>
1193+ mathInlineWith "\\(" "\\)")
1194+ <|> (guardEnabled Ext_tex_math_double_backslash >>
1195+ mathInlineWith "\\\\(" "\\\\)")
1196+
1197+mathInlineWith :: String -> String -> Parser [Char] ParserState String
1198+mathInlineWith op cl = try $ do
1199+ string op
1195 notFollowedBy space
1200 notFollowedBy space
1201+ words' <- many1Till (count 1 (noneOf "\n\\")
1202+ <|> (char '\\' >> anyChar >>= \c -> return ['\\',c])
1196− words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline)))
1203+ <|> count 1 newline <* notFollowedBy' blankline
1197− char '$'
1204+ *> return " ")
1205+ (try $ string cl)
1198− notFollowedBy digit
1206+ notFollowedBy digit -- to prevent capture of $5
1199− return $ intercalate " " words'
1207+ return $ concat words'
1200
1208
1201-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1209-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1202-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1210-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub