diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-07 19:16:56 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-07 19:16:56 +0100 |
commit | 9db98550dfc39d31072e43ac066154a483865fc4 (patch) | |
tree | d586df1d38f058bbfad712664c2db588a705d2b1 /src | |
parent | f10dd380bbb86cc2cf9680c9dee92e34092dc273 (diff) | |
download | pandoc-9db98550dfc39d31072e43ac066154a483865fc4.tar.gz |
Refactored include file handling in LaTeX reader.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 30 |
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 |