git.iko.soy/typeable/pandoc
on master help sign in
Mediawiki reader: improve table parsing.

This fixes detection of table attributes and also handles `!` characters in cells. Closes #4508.

commit5a79948e0c689ffbcb91355a5575bc46464fa8d2 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 28 Mar 2018, 08:59 (9 years ago) parentd0a7dbd
2 files changed+29−14
src/Text/Pandoc/Readers/MediaWiki.hs+18−5 test/command/2649.md+11−9
src/Text/Pandoc/Readers/MediaWiki.hs+18−5
@@ -232,7 +232,8 @@ para = do
232232table :: PandocMonad m => MWParser m Blocks
233233table = do
234234 tableStart
235− styles <- option [] parseAttrs
235+ styles <- option [] $
236+ parseAttrs <* skipMany spaceChar <* optional (char '|')
236237 skipMany spaceChar
237238 optional blanklines
238239 let tableWidth = case lookup "width" styles of
@@ -283,17 +284,29 @@ rowsep = try $ guardColumnOne *> skipSpaces *> sym "|-" <*
283284
284285cellsep :: PandocMonad m => MWParser m ()
285286cellsep = try $ do
287+ col <- sourceColumn <$> getPosition
286288 skipSpaces
287− (char '|' *> notFollowedBy (oneOf "-}+") *> optional (char '|'))
288− <|> (char '!' *> optional (char '!'))
289+ let pipeSep = do
290+ char '|'
291+ notFollowedBy (oneOf "-}+")
292+ if col == 1
293+ then optional (char '|')
294+ else void (char '|')
295+ let exclSep = do
296+ char '!'
297+ if col == 1
298+ then optional (char '!')
299+ else void (char '!')
300+ pipeSep <|> exclSep
289301
290302tableCaption :: PandocMonad m => MWParser m Inlines
291303tableCaption = try $ do
292304 guardColumnOne
293305 skipSpaces
294306 sym "|+"
295− optional (try $ parseAttr *> skipSpaces *> char '|' *> skipSpaces)
296− (trimInlines . mconcat) <$> many (notFollowedBy (cellsep <|> rowsep) *> inline)
307+ optional (try $ parseAttr *> skipSpaces *> char '|' *> blanklines)
308+ (trimInlines . mconcat) <$>
309+ many (notFollowedBy (cellsep <|> rowsep) *> inline)
297310
298311tableRow :: PandocMonad m => MWParser m [((Alignment, Double), Blocks)]
299312tableRow = try $ skipMany htmlComment *> many tableCell
test/command/2649.md+11−9
@@ -67,7 +67,8 @@
6767! Aantal
6868|-
6969| 1
70−|align=left| {{FR-VLAG}} [[Sébastien Loeb]] | 78
70+|align=left| {{FR-VLAG}} [[Sébastien Loeb]]
71+| 78
7172|-
7273| 2
7374|align=left| {{FR-VLAG}} '''[[Sébastien Ogier]]'''
@@ -79,24 +80,25 @@
7980|}
8081^D
8182<table>
83+<thead>
84+<tr class="header">
85+<th><p>Plaats</p></th>
86+<th><p>Rijder</p></th>
87+<th><p>Aantal</p></th>
88+</tr>
89+</thead>
8290<tbody>
8391<tr class="odd">
84−<td></td>
85−<td><p>Plaats</p></td>
86−<td><p>Rijder</p></td>
87−<td><p>Aantal</p></td>
88−</tr>
89−<tr class="even">
9092<td><p>1</p></td>
9193<td><p><a href="Sébastien_Loeb" title="wikilink">Sébastien Loeb</a></p></td>
9294<td><p>78</p></td>
9395</tr>
94−<tr class="odd">
96+<tr class="even">
9597<td><p>2</p></td>
9698<td><p><strong><a href="Sébastien_Ogier" title="wikilink">Sébastien Ogier</a></strong></p></td>
9799<td><p>38</p></td>
98100</tr>
99−<tr class="even">
101+<tr class="odd">
100102<td><p>10</p></td>
101103<td><p><a href="Hannu_Mikkola" title="wikilink">Hannu Mikkola</a></p></td>
102104<td><p>18</p></td>