aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-07 19:16:56 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-07 19:16:56 +0100
commit9db98550dfc39d31072e43ac066154a483865fc4 (patch)
treed586df1d38f058bbfad712664c2db588a705d2b1
parentf10dd380bbb86cc2cf9680c9dee92e34092dc273 (diff)
downloadpandoc-9db98550dfc39d31072e43ac066154a483865fc4.tar.gz
Refactored include file handling in LaTeX reader.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index ea284efef..5950ec852 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -960,22 +960,24 @@ include = do
return $ if name == "usepackage"
then map (maybeAddExtension ".sty") fs
else map (maybeAddExtension ".tex") fs
+ mconcat <$> mapM insertIncludedFile fs'
+
+insertIncludedFile :: PandocMonad m => FilePath -> LP m Blocks
+insertIncludedFile f = do
oldPos <- getPosition
oldInput <- getInput
- -- now process each include file in order...
- mconcat <$> forM fs' (\f -> do
- containers <- stateContainers <$> getState
- when (f `elem` containers) $
- throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
- updateState $ \s -> s{ stateContainers = f : stateContainers s }
- contents <- lift $ readTeXFile f
- setPosition $ newPos f 1 1
- setInput contents
- bs <- blocks
- setInput oldInput
- setPosition oldPos
- updateState $ \s -> s{ stateContainers = tail $ stateContainers s }
- return bs)
+ containers <- stateContainers <$> getState
+ when (f `elem` containers) $
+ throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
+ updateState $ \s -> s{ stateContainers = f : stateContainers s }
+ contents <- lift $ readTeXFile f
+ setPosition $ newPos f 1 1
+ setInput contents
+ bs <- blocks
+ setInput oldInput
+ setPosition oldPos
+ updateState $ \s -> s{ stateContainers = tail $ stateContainers s }
+ return bs
readTeXFile :: PandocMonad m => FilePath -> m String
readTeXFile f = do