From 5aa73bd0a2820a0c89b5990dbe53abfdd5ade32d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 7 Mar 2021 15:49:02 -0800 Subject: LaTeX reader: handle table cells containing `&` in `\verb`. Closes #7129. --- src/Text/Pandoc/Readers/LaTeX/Table.hs | 7 ++++++- test/command/7129.md | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/command/7129.md diff --git a/src/Text/Pandoc/Readers/LaTeX/Table.hs b/src/Text/Pandoc/Readers/LaTeX/Table.hs index 2ea9caf58..7833da081 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Table.hs @@ -134,6 +134,11 @@ parseTableRow :: PandocMonad m -> LP m Row parseTableRow blocks inline envname prefsufs = do notFollowedBy (spaces *> end_ envname) + -- contexts that can contain & that is not colsep: + let canContainAmp (Tok _ (CtrlSeq "begin") _) = True + canContainAmp (Tok _ (CtrlSeq "verb") _) = True + canContainAmp (Tok _ (CtrlSeq "Verb") _) = True + canContainAmp _ = False -- add prefixes and suffixes in token stream: let celltoks (pref, suff) = do prefpos <- getPosition @@ -142,7 +147,7 @@ parseTableRow blocks inline envname prefsufs = do ((lookAhead (controlSeq "parbox") >> void blocks) -- #5711 <|> - (lookAhead (controlSeq "begin") >> void inline) + (lookAhead (satisfyTok canContainAmp) >> void inline) <|> (lookAhead (symbol '$') >> void inline)) <|> diff --git a/test/command/7129.md b/test/command/7129.md new file mode 100644 index 000000000..fef4ca2c3 --- /dev/null +++ b/test/command/7129.md @@ -0,0 +1,27 @@ +``` +% pandoc -f latex -t native +\begin{tabular}{ll} \hline + FOO & BAR \\ \hline + foo & \verb|b&r| \\ \hline +\end{tabular} +^D +[Table ("",[],[]) (Caption Nothing + []) + [(AlignLeft,ColWidthDefault) + ,(AlignLeft,ColWidthDefault)] + (TableHead ("",[],[]) + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Plain [Str "FOO"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Plain [Str "BAR"]]]]) + [(TableBody ("",[],[]) (RowHeadColumns 0) + [] + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Plain [Str "foo"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Plain [Code ("",[],[]) "b&r"]]]])] + (TableFoot ("",[],[]) + [])] +``` -- cgit v1.2.3