git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: handle table cells containing `&` in `\verb`.

Closes #7129.

commitcbdecdf865fe58ed7cb6c90e1329b7166744f1be authorJohn MacFarlane <jgm@berkeley.edu> dateSun 7 Mar 2021, 15:49 (6 years ago) parent1288d29
2 files changed+33−1
src/Text/Pandoc/Readers/LaTeX/Table.hs+6−1 test/command/7129.md+27
src/Text/Pandoc/Readers/LaTeX/Table.hs+6−1
@@ -134,6 +134,11 @@ parseTableRow :: PandocMonad m
134134 -> LP m Row
135135parseTableRow blocks inline envname prefsufs = do
136136 notFollowedBy (spaces *> end_ envname)
137+ -- contexts that can contain & that is not colsep:
138+ let canContainAmp (Tok _ (CtrlSeq "begin") _) = True
139+ canContainAmp (Tok _ (CtrlSeq "verb") _) = True
140+ canContainAmp (Tok _ (CtrlSeq "Verb") _) = True
141+ canContainAmp _ = False
137142 -- add prefixes and suffixes in token stream:
138143 let celltoks (pref, suff) = do
139144 prefpos <- getPosition
@@ -142,7 +147,7 @@ parseTableRow blocks inline envname prefsufs = do
142147 ((lookAhead (controlSeq "parbox") >>
143148 void blocks) -- #5711
144149 <|>
145− (lookAhead (controlSeq "begin") >> void inline)
150+ (lookAhead (satisfyTok canContainAmp) >> void inline)
146151 <|>
147152 (lookAhead (symbol '$') >> void inline))
148153 <|>
test/command/7129.mdnew file+27
@@ -0,0 +1,27 @@
1+```
2+% pandoc -f latex -t native
3+\begin{tabular}{ll} \hline
4+ FOO & BAR \\ \hline
5+ foo & \verb|b&r| \\ \hline
6+\end{tabular}
7+^D
8+[Table ("",[],[]) (Caption Nothing
9+ [])
10+ [(AlignLeft,ColWidthDefault)
11+ ,(AlignLeft,ColWidthDefault)]
12+ (TableHead ("",[],[])
13+ [Row ("",[],[])
14+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
15+ [Plain [Str "FOO"]]
16+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
17+ [Plain [Str "BAR"]]]])
18+ [(TableBody ("",[],[]) (RowHeadColumns 0)
19+ []
20+ [Row ("",[],[])
21+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
22+ [Plain [Str "foo"]]
23+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
24+ [Plain [Code ("",[],[]) "b&r"]]]])]
25+ (TableFoot ("",[],[])
26+ [])]
27+```