summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-22 16:45:13 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-22 18:03:51 -0800
commit9daf22fa615ad49b675e4e3aae722c982eb4cce3 (patch)
treebacdfb3e50028f68caa325e279bb469cd3aaa2ba /src
parentdd217f75e50fdfaf990dd2ccbd08e42230765056 (diff)
LaTeX reader: Refactored inlineCommand.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index e6ae4c11b..a43f3d572 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -237,19 +237,21 @@ withVerbatimMode parser = do
return result
rawLaTeXParser :: (PandocMonad m, HasMacros s, HasReaderOptions s)
- => LP m a -> ParserT String s m String
+ => LP m a -> ParserT String s m (a, String)
rawLaTeXParser parser = do
inp <- getInput
let toks = tokenize "source" $ T.pack inp
pstate <- getState
- let lstate = def{ sOptions = extractReaderOptions pstate }
- res <- lift $ runParserT ((,) <$> try (snd <$> withRaw parser) <*> getState)
- lstate "source" toks
+ let lstate = def{ sOptions = extractReaderOptions pstate
+ , sMacros = extractMacros pstate }
+ let rawparser = (,) <$> withRaw parser <*> getState
+ res <- lift $ runParserT rawparser lstate "chunk" toks
case res of
Left _ -> mzero
- Right (raw, st) -> do
+ Right ((val, raw), st) -> do
updateState (updateMacros (sMacros st <>))
- takeP (T.length (untokenize raw))
+ rawstring <- takeP (T.length (untokenize raw))
+ return (val, rawstring)
applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> String -> ParserT String s m String
@@ -268,33 +270,18 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParserT String s m String
rawLaTeXBlock = do
lookAhead (try (char '\\' >> letter))
- rawLaTeXParser (environment <|> macroDef <|> blockCommand)
+ snd <$> rawLaTeXParser (environment <|> macroDef <|> blockCommand)
rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParserT String s m String
rawLaTeXInline = do
lookAhead (try (char '\\' >> letter) <|> char '$')
- rawLaTeXParser (inlineEnvironment <|> inlineCommand')
+ snd <$> rawLaTeXParser (inlineEnvironment <|> inlineCommand')
inlineCommand :: PandocMonad m => ParserT String ParserState m Inlines
inlineCommand = do
lookAhead (try (char '\\' >> letter) <|> char '$')
- inp <- getInput
- let toks = tokenize "chunk" $ T.pack inp
- let rawinline = do
- (il, raw) <- try $ withRaw (inlineEnvironment <|> inlineCommand')
- st <- getState
- return (il, raw, st)
- pstate <- getState
- let lstate = def{ sOptions = extractReaderOptions pstate
- , sMacros = extractMacros pstate }
- res <- runParserT rawinline lstate "source" toks
- case res of
- Left _ -> mzero
- Right (il, raw, s) -> do
- updateState $ updateMacros (const $ sMacros s)
- takeP (T.length (untokenize raw))
- return il
+ fst <$> rawLaTeXParser (inlineEnvironment <|> inlineCommand')
tokenize :: SourceName -> Text -> [Tok]
tokenize sourcename = totoks (initialPos sourcename)