LaTeX-parser: restrict \endinput to current file

This commit is contained in:
Simon Schuster 2021-08-20 16:41:50 +02:00 committed by John MacFarlane
parent d05460d00d
commit 591cdca38b
5 changed files with 27 additions and 1 deletions

View file

@ -242,6 +242,7 @@ extra-source-files:
test/command/sub-file-chapter-1.tex test/command/sub-file-chapter-1.tex
test/command/sub-file-chapter-2.tex test/command/sub-file-chapter-2.tex
test/command/bar.tex test/command/bar.tex
test/command/bar-endinput.tex
test/command/yaml-metadata.yaml test/command/yaml-metadata.yaml
test/command/3510-subdoc.org test/command/3510-subdoc.org
test/command/3510-export.latex test/command/3510-export.latex

View file

@ -890,7 +890,7 @@ blockCommands = M.fromList
addMeta "bibliography" . splitBibs . untokenize)) addMeta "bibliography" . splitBibs . untokenize))
, ("addbibresource", mempty <$ (skipopts *> braced >>= , ("addbibresource", mempty <$ (skipopts *> braced >>=
addMeta "bibliography" . splitBibs . untokenize)) addMeta "bibliography" . splitBibs . untokenize))
, ("endinput", mempty <$ skipMany anyTok) , ("endinput", mempty <$ skipSameFileToks)
-- includes -- includes
, ("lstinputlisting", inputListing) , ("lstinputlisting", inputListing)
, ("inputminted", inputMinted) , ("inputminted", inputMinted)
@ -921,6 +921,10 @@ blockCommands = M.fromList
, ("epigraph", epigraph) , ("epigraph", epigraph)
] ]
skipSameFileToks :: PandocMonad m => LP m ()
skipSameFileToks = do
pos <- getPosition
skipMany $ infile (sourceName pos)
environments :: PandocMonad m => M.Map Text (LP m Blocks) environments :: PandocMonad m => M.Map Text (LP m Blocks)
environments = M.union (tableEnvironments blocks inline) $ environments = M.union (tableEnvironments blocks inline) $

View file

@ -45,6 +45,7 @@ module Text.Pandoc.Readers.LaTeX.Parsing
, isNewlineTok , isNewlineTok
, isWordTok , isWordTok
, isArgTok , isArgTok
, infile
, spaces , spaces
, spaces1 , spaces1
, tokTypeIn , tokTypeIn
@ -646,6 +647,9 @@ isArgTok :: Tok -> Bool
isArgTok (Tok _ (Arg _) _) = True isArgTok (Tok _ (Arg _) _) = True
isArgTok _ = False isArgTok _ = False
infile :: PandocMonad m => SourceName -> LP m Tok
infile reference = satisfyTok (\(Tok source _ _) -> (sourceName source) == reference)
spaces :: PandocMonad m => LP m () spaces :: PandocMonad m => LP m ()
spaces = skipMany (satisfyTok (tokTypeIn [Comment, Spaces, Newline])) spaces = skipMany (satisfyTok (tokTypeIn [Comment, Spaces, Newline]))

View file

@ -0,0 +1,3 @@
\emph{hi there}
\endinput
\emph{invisible}

View file

@ -0,0 +1,14 @@
```
% pandoc --from=latex -t native
\begin{document}
Visible
\include{command/bar-endinput}
Visible
\end{document}
^D
[Para [Str "Visible"]
,Para [Emph [Str "hi",Space,Str "there"]]
,Para [Str "Visible"]]
```