git.iko.soy/typeable/pandoc
on master help sign in
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

commit14dc5206697539cd8f9afc2b5c640ed2df319a1a authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateWed 29 Aug 2007, 21:03 (19 years ago) parent451b426
1 file changed+24−24
src/Text/Pandoc/Readers/LaTeX.hs+24−24
src/Text/Pandoc/Readers/LaTeX.hs+24−24
@@ -47,7 +47,7 @@ readLaTeX :: ParserState -- ^ Parser state, including options for parser
4747readLaTeX = readWith parseLaTeX
4848
4949-- characters with special meaning
50−specialChars = "\\$%^&_~#{}\n \t|<>'\"-"
50+specialChars = "\\`$%^&_~#{}\n \t|<>'\"-"
5151
5252--
5353-- utility functions
@@ -69,7 +69,7 @@ isArg other = False
6969commandArgs = many optOrArg
7070
7171-- | Parses LaTeX command, returns (name, star, list of options or arguments).
72−command = try $ do
72+command = do
7373 char '\\'
7474 name <- many1 alphaNum
7575 star <- option "" (string "*") -- some commands have starred versions
@@ -152,16 +152,15 @@ block = choice [ hrule
152152-- header blocks
153153--
154154
155−header = choice (map headerLevel (enumFromTo 1 5)) <?> "header"
156−
157−headerLevel n = try $ do
158− let subs = concat $ replicate (n - 1) "sub"
159− string ("\\" ++ subs ++ "section")
155+header = try $ do
156+ char '\\'
157+ subs <- many (try (string "sub"))
158+ string "section"
160159 optional (char '*')
161160 char '{'
162161 title <- manyTill inline (char '}')
163162 spaces
164− return $ Header n (normalizeSpaces title)
163+ return $ Header (length subs + 1) (normalizeSpaces title)
165164
166165--
167166-- hrule block
@@ -386,7 +385,18 @@ comment = try $ char '%' >> manyTill anyChar newline >> spaces >> return Null
386385-- inline
387386--
388387
389−inline = choice [ strong
388+inline = choice [ str
389+ , endline
390+ , whitespace
391+ , quoted
392+ , apostrophe
393+ , spacer
394+ , strong
395+ , math
396+ , ellipses
397+ , emDash
398+ , enDash
399+ , hyphen
390400 , emph
391401 , strikeout
392402 , superscript
@@ -394,27 +404,17 @@ inline = choice [ strong
394404 , ref
395405 , lab
396406 , code
397− , linebreak
398− , spacer
399− , math
400− , ellipses
401− , emDash
402− , enDash
403− , hyphen
404− , quoted
405− , apostrophe
406− , accentedChar
407− , specialChar
408407 , url
409408 , link
410409 , image
411410 , footnote
411+ , linebreak
412+ , accentedChar
413+ , specialChar
412414 , rawLaTeXInline
413415 , escapedChar
414416 , unescapedChar
415− , str
416− , endline
417− , whitespace ] <?> "inline"
417+ ] <?> "inline"
418418
419419accentedChar = normalAccentedChar <|> specialAccentedChar
420420
@@ -492,7 +492,7 @@ escapedChar = do
492492 return $ if result == Str "\n" then Str " " else result
493493
494494-- ignore standalone, nonescaped special characters
495−unescapedChar = oneOf "$^&_#{}|<>" >> return (Str "")
495+unescapedChar = oneOf "`$^&_#{}|<>" >> return (Str "")
496496
497497specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
498498