Cleaned up LaTeX reader.
Rearranged order of parsers in inline for slight speed improvement. Added ` to special characters and 'unescapedChar'. git-svn-id: https://pandoc.googlecode.com/svn/trunk@960 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
451b426fd6
commit
14dc520669
1 changed files with 24 additions and 24 deletions
|
@ -47,7 +47,7 @@ readLaTeX :: ParserState -- ^ Parser state, including options for parser
|
||||||
readLaTeX = readWith parseLaTeX
|
readLaTeX = readWith parseLaTeX
|
||||||
|
|
||||||
-- characters with special meaning
|
-- characters with special meaning
|
||||||
specialChars = "\\$%^&_~#{}\n \t|<>'\"-"
|
specialChars = "\\`$%^&_~#{}\n \t|<>'\"-"
|
||||||
|
|
||||||
--
|
--
|
||||||
-- utility functions
|
-- utility functions
|
||||||
|
@ -69,7 +69,7 @@ isArg other = False
|
||||||
commandArgs = many optOrArg
|
commandArgs = many optOrArg
|
||||||
|
|
||||||
-- | Parses LaTeX command, returns (name, star, list of options or arguments).
|
-- | Parses LaTeX command, returns (name, star, list of options or arguments).
|
||||||
command = try $ do
|
command = do
|
||||||
char '\\'
|
char '\\'
|
||||||
name <- many1 alphaNum
|
name <- many1 alphaNum
|
||||||
star <- option "" (string "*") -- some commands have starred versions
|
star <- option "" (string "*") -- some commands have starred versions
|
||||||
|
@ -152,16 +152,15 @@ block = choice [ hrule
|
||||||
-- header blocks
|
-- header blocks
|
||||||
--
|
--
|
||||||
|
|
||||||
header = choice (map headerLevel (enumFromTo 1 5)) <?> "header"
|
header = try $ do
|
||||||
|
char '\\'
|
||||||
headerLevel n = try $ do
|
subs <- many (try (string "sub"))
|
||||||
let subs = concat $ replicate (n - 1) "sub"
|
string "section"
|
||||||
string ("\\" ++ subs ++ "section")
|
|
||||||
optional (char '*')
|
optional (char '*')
|
||||||
char '{'
|
char '{'
|
||||||
title <- manyTill inline (char '}')
|
title <- manyTill inline (char '}')
|
||||||
spaces
|
spaces
|
||||||
return $ Header n (normalizeSpaces title)
|
return $ Header (length subs + 1) (normalizeSpaces title)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- hrule block
|
-- hrule block
|
||||||
|
@ -386,7 +385,18 @@ comment = try $ char '%' >> manyTill anyChar newline >> spaces >> return Null
|
||||||
-- inline
|
-- inline
|
||||||
--
|
--
|
||||||
|
|
||||||
inline = choice [ strong
|
inline = choice [ str
|
||||||
|
, endline
|
||||||
|
, whitespace
|
||||||
|
, quoted
|
||||||
|
, apostrophe
|
||||||
|
, spacer
|
||||||
|
, strong
|
||||||
|
, math
|
||||||
|
, ellipses
|
||||||
|
, emDash
|
||||||
|
, enDash
|
||||||
|
, hyphen
|
||||||
, emph
|
, emph
|
||||||
, strikeout
|
, strikeout
|
||||||
, superscript
|
, superscript
|
||||||
|
@ -394,27 +404,17 @@ inline = choice [ strong
|
||||||
, ref
|
, ref
|
||||||
, lab
|
, lab
|
||||||
, code
|
, code
|
||||||
, linebreak
|
|
||||||
, spacer
|
|
||||||
, math
|
|
||||||
, ellipses
|
|
||||||
, emDash
|
|
||||||
, enDash
|
|
||||||
, hyphen
|
|
||||||
, quoted
|
|
||||||
, apostrophe
|
|
||||||
, accentedChar
|
|
||||||
, specialChar
|
|
||||||
, url
|
, url
|
||||||
, link
|
, link
|
||||||
, image
|
, image
|
||||||
, footnote
|
, footnote
|
||||||
|
, linebreak
|
||||||
|
, accentedChar
|
||||||
|
, specialChar
|
||||||
, rawLaTeXInline
|
, rawLaTeXInline
|
||||||
, escapedChar
|
, escapedChar
|
||||||
, unescapedChar
|
, unescapedChar
|
||||||
, str
|
] <?> "inline"
|
||||||
, endline
|
|
||||||
, whitespace ] <?> "inline"
|
|
||||||
|
|
||||||
accentedChar = normalAccentedChar <|> specialAccentedChar
|
accentedChar = normalAccentedChar <|> specialAccentedChar
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ escapedChar = do
|
||||||
return $ if result == Str "\n" then Str " " else result
|
return $ if result == Str "\n" then Str " " else result
|
||||||
|
|
||||||
-- ignore standalone, nonescaped special characters
|
-- ignore standalone, nonescaped special characters
|
||||||
unescapedChar = oneOf "$^&_#{}|<>" >> return (Str "")
|
unescapedChar = oneOf "`$^&_#{}|<>" >> return (Str "")
|
||||||
|
|
||||||
specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
|
specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue