git.iko.soy/typeable/pandoc
on master help sign in
Cleaned up LaTeX reader.
14dc520fiddlosopher
src/Text/Pandoc/Readers/LaTeX.hs+24−24
@@ -47,7 +47,7 @@ readLaTeX :: ParserState -- ^ Parser state, including options for parser
47readLaTeX = readWith parseLaTeX
47readLaTeX = readWith parseLaTeX
48
48
49-- characters with special meaning
49-- characters with special meaning
50−specialChars = "\\$%^&_~#{}\n \t|<>'\"-"
50+specialChars = "\\`$%^&_~#{}\n \t|<>'\"-"
51
51
52--
52--
53-- utility functions
53-- utility functions
@@ -69,7 +69,7 @@ isArg other = False
69commandArgs = many optOrArg
69commandArgs = many optOrArg
70
70
71-- | Parses LaTeX command, returns (name, star, list of options or arguments).
71-- | Parses LaTeX command, returns (name, star, list of options or arguments).
72−command = try $ do
72+command = do
73 char '\\'
73 char '\\'
74 name <- many1 alphaNum
74 name <- many1 alphaNum
75 star <- option "" (string "*") -- some commands have starred versions
75 star <- option "" (string "*") -- some commands have starred versions
@@ -152,16 +152,15 @@ block = choice [ hrule
152-- header blocks
152-- header blocks
153--
153--
154
154
155−header = choice (map headerLevel (enumFromTo 1 5)) <?> "header"
155+header = try $ do
156−
156+ char '\\'
157−headerLevel n = try $ do
157+ subs <- many (try (string "sub"))
158− let subs = concat $ replicate (n - 1) "sub"
159− string ("\\" ++ subs ++ "section")
158+ string "section"
160 optional (char '*')
159 optional (char '*')
161 char '{'
160 char '{'
162 title <- manyTill inline (char '}')
161 title <- manyTill inline (char '}')
163 spaces
162 spaces
164− return $ Header n (normalizeSpaces title)
163+ return $ Header (length subs + 1) (normalizeSpaces title)
165
164
166--
165--
167-- hrule block
166-- hrule block
@@ -386,7 +385,18 @@ comment = try $ char '%' >> manyTill anyChar newline >> spaces >> return Null
386-- inline
385-- inline
387--
386--
388
387
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
390 , emph
400 , emph
391 , strikeout
401 , strikeout
392 , superscript
402 , superscript
@@ -394,27 +404,17 @@ inline = choice [ strong
394 , ref
404 , ref
395 , lab
405 , lab
396 , code
406 , code
397− , linebreak
398− , spacer
399− , math
400− , ellipses
401− , emDash
402− , enDash
403− , hyphen
404− , quoted
405− , apostrophe
406− , accentedChar
407− , specialChar
408 , url
407 , url
409 , link
408 , link
410 , image
409 , image
411 , footnote
410 , footnote
411+ , linebreak
412+ , accentedChar
413+ , specialChar
412 , rawLaTeXInline
414 , rawLaTeXInline
413 , escapedChar
415 , escapedChar
414 , unescapedChar
416 , unescapedChar
415− , str
416− , endline
417− , whitespace ] <?> "inline"
417+ ] <?> "inline"
418
418
419accentedChar = normalAccentedChar <|> specialAccentedChar
419accentedChar = normalAccentedChar <|> specialAccentedChar
420
420
@@ -492,7 +492,7 @@ escapedChar = do
492 return $ if result == Str "\n" then Str " " else result
492 return $ if result == Str "\n" then Str " " else result
493
493
494-- ignore standalone, nonescaped special characters
494-- ignore standalone, nonescaped special characters
495−unescapedChar = oneOf "$^&_#{}|<>" >> return (Str "")
495+unescapedChar = oneOf "`$^&_#{}|<>" >> return (Str "")
496
496
497specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
497specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
498
498