git.iko.soy/typeable/pandoc
on master help sign in
Mediawiki reader: improve table parsing.
5a79948John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+18−5
@@ -232,7 +232,8 @@ para = do
232table :: PandocMonad m => MWParser m Blocks
232table :: PandocMonad m => MWParser m Blocks
233table = do
233table = do
234 tableStart
234 tableStart
235− styles <- option [] parseAttrs
235+ styles <- option [] $
236+ parseAttrs <* skipMany spaceChar <* optional (char '|')
236 skipMany spaceChar
237 skipMany spaceChar
237 optional blanklines
238 optional blanklines
238 let tableWidth = case lookup "width" styles of
239 let tableWidth = case lookup "width" styles of
@@ -283,17 +284,29 @@ rowsep = try $ guardColumnOne *> skipSpaces *> sym "|-" <*
283
284
284cellsep :: PandocMonad m => MWParser m ()
285cellsep :: PandocMonad m => MWParser m ()
285cellsep = try $ do
286cellsep = try $ do
287+ col <- sourceColumn <$> getPosition
286 skipSpaces
288 skipSpaces
289+ let pipeSep = do
290+ char '|'
287− (char '|' *> notFollowedBy (oneOf "-}+") *> optional (char '|'))
291+ notFollowedBy (oneOf "-}+")
288− <|> (char '!' *> optional (char '!'))
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
289
301
290tableCaption :: PandocMonad m => MWParser m Inlines
302tableCaption :: PandocMonad m => MWParser m Inlines
291tableCaption = try $ do
303tableCaption = try $ do
292 guardColumnOne
304 guardColumnOne
293 skipSpaces
305 skipSpaces
294 sym "|+"
306 sym "|+"
295− optional (try $ parseAttr *> skipSpaces *> char '|' *> skipSpaces)
307+ optional (try $ parseAttr *> skipSpaces *> char '|' *> blanklines)
308+ (trimInlines . mconcat) <$>
296− (trimInlines . mconcat) <$> many (notFollowedBy (cellsep <|> rowsep) *> inline)
309+ many (notFollowedBy (cellsep <|> rowsep) *> inline)
297
310
298tableRow :: PandocMonad m => MWParser m [((Alignment, Double), Blocks)]
311tableRow :: PandocMonad m => MWParser m [((Alignment, Double), Blocks)]
299tableRow = try $ skipMany htmlComment *> many tableCell
312tableRow = try $ skipMany htmlComment *> many tableCell
test/command/2649.md+11−9
@@ -67,7 +67,8 @@
67! Aantal
67! Aantal
68|-
68|-
69| 1
69| 1
70−|align=left| {{FR-VLAG}} [[Sébastien Loeb]] | 78
70+|align=left| {{FR-VLAG}} [[Sébastien Loeb]]
71+| 78
71|-
72|-
72| 2
73| 2
73|align=left| {{FR-VLAG}} '''[[Sébastien Ogier]]'''
74|align=left| {{FR-VLAG}} '''[[Sébastien Ogier]]'''
@@ -79,24 +80,25 @@
79|}
80|}
80^D
81^D
81<table>
82<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>
82<tbody>
90<tbody>
83<tr class="odd">
91<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">
90<td><p>1</p></td>
92<td><p>1</p></td>
91<td><p><a href="Sébastien_Loeb" title="wikilink">Sébastien Loeb</a></p></td>
93<td><p><a href="Sébastien_Loeb" title="wikilink">Sébastien Loeb</a></p></td>
92<td><p>78</p></td>
94<td><p>78</p></td>
93</tr>
95</tr>
94−<tr class="odd">
96+<tr class="even">
95<td><p>2</p></td>
97<td><p>2</p></td>
96<td><p><strong><a href="Sébastien_Ogier" title="wikilink">Sébastien Ogier</a></strong></p></td>
98<td><p><strong><a href="Sébastien_Ogier" title="wikilink">Sébastien Ogier</a></strong></p></td>
97<td><p>38</p></td>
99<td><p>38</p></td>
98</tr>
100</tr>
99−<tr class="even">
101+<tr class="odd">
100<td><p>10</p></td>
102<td><p>10</p></td>
101<td><p><a href="Hannu_Mikkola" title="wikilink">Hannu Mikkola</a></p></td>
103<td><p><a href="Hannu_Mikkola" title="wikilink">Hannu Mikkola</a></p></td>
102<td><p>18</p></td>
104<td><p>18</p></td>