git.iko.soy/typeable/pandoc
on master help sign in
Refactored include file handling in LaTeX reader.
commit9db98550dfc39d31072e43ac066154a483865fc4 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Feb 2017, 19:16 (10 years ago) parentf10dd38
1 file changed+16−14
src/Text/Pandoc/Readers/LaTeX.hs+16−14
src/Text/Pandoc/Readers/LaTeX.hs+16−14
@@ -960,22 +960,24 @@ include = do
960960 return $ if name == "usepackage"
961961 then map (maybeAddExtension ".sty") fs
962962 else map (maybeAddExtension ".tex") fs
963+ mconcat <$> mapM insertIncludedFile fs'
964+
965+insertIncludedFile :: PandocMonad m => FilePath -> LP m Blocks
966+insertIncludedFile f = do
963967 oldPos <- getPosition
964968 oldInput <- getInput
965− -- now process each include file in order...
966− mconcat <$> forM fs' (\f -> do
967− containers <- stateContainers <$> getState
968− when (f `elem` containers) $
969− throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
970− updateState $ \s -> s{ stateContainers = f : stateContainers s }
971− contents <- lift $ readTeXFile f
972− setPosition $ newPos f 1 1
973− setInput contents
974− bs <- blocks
975− setInput oldInput
976− setPosition oldPos
977− updateState $ \s -> s{ stateContainers = tail $ stateContainers s }
978− return bs)
969+ containers <- stateContainers <$> getState
970+ when (f `elem` containers) $
971+ throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
972+ updateState $ \s -> s{ stateContainers = f : stateContainers s }
973+ contents <- lift $ readTeXFile f
974+ setPosition $ newPos f 1 1
975+ setInput contents
976+ bs <- blocks
977+ setInput oldInput
978+ setPosition oldPos
979+ updateState $ \s -> s{ stateContainers = tail $ stateContainers s }
980+ return bs
979981
980982readTeXFile :: PandocMonad m => FilePath -> m String
981983readTeXFile f = do