git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Table improvements, added simple table tests.
ce509beJohn MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+9−4
@@ -171,7 +171,7 @@ table = do
171 rows' <- many $ try $ rowsep *> tableRow
171 rows' <- many $ try $ rowsep *> tableRow
172 tableEnd
172 tableEnd
173 -- TODO handle cellspecs from styles and aligns...
173 -- TODO handle cellspecs from styles and aligns...
174− let cols = length $ head rows'
174+ let cols = length hdr
175 let (headers,rows) = if hasheader
175 let (headers,rows) = if hasheader
176 then (hdr, rows')
176 then (hdr, rows')
177 else (replicate cols mempty, hdr:rows')
177 else (replicate cols mempty, hdr:rows')
@@ -197,11 +197,12 @@ tableCaption = try $ guardColumnOne *> sym "|+" *> skipMany spaceChar *>
197 (trimInlines . mconcat <$> (many inline)) <* skipMany blankline
197 (trimInlines . mconcat <$> (many inline)) <* skipMany blankline
198
198
199tableRow :: MWParser [Blocks]
199tableRow :: MWParser [Blocks]
200−tableRow = try $ many tableCell <* skipMany blankline
200+tableRow = try $ many tableCell
201
201
202tableCell :: MWParser Blocks
202tableCell :: MWParser Blocks
203tableCell =
203tableCell =
204− try $ cellsep *> skipMany spaceChar *> (mconcat <$> (many block))
204+ try $ cellsep *> skipMany spaceChar *>
205+ (mconcat <$> (many $ notFollowedBy (cellsep <|> rowsep <|> tableEnd) *> block))
205
206
206template :: MWParser Blocks
207template :: MWParser Blocks
207template = B.rawBlock "mediawiki" <$> doublebrackets
208template = B.rawBlock "mediawiki" <$> doublebrackets
@@ -405,7 +406,9 @@ inlineTag = do
405
406
406special :: MWParser Inlines
407special :: MWParser Inlines
407special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
408special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
409+-- notFollowedBy (tableStart <|> tableEnd
410+-- <|> cellsep <|> rowsep) *>
408− notFollowedBy (char '|') *> oneOf specialChars)
411+ oneOf specialChars)
409
412
410inlineHtml :: MWParser Inlines
413inlineHtml :: MWParser Inlines
411inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
414inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
@@ -418,8 +421,10 @@ endline = () <$ try (newline <*
418 notFollowedBy blankline <*
421 notFollowedBy blankline <*
419 notFollowedBy' hrule <*
422 notFollowedBy' hrule <*
420 notFollowedBy tableStart <*
423 notFollowedBy tableStart <*
424+ notFollowedBy tableEnd <*
421 notFollowedBy' template <*
425 notFollowedBy' template <*
422 notFollowedBy cellsep <*
426 notFollowedBy cellsep <*
427+ notFollowedBy rowsep <*
423 notFollowedBy anyListStart)
428 notFollowedBy anyListStart)
424
429
425image :: MWParser Inlines
430image :: MWParser Inlines
tests/mediawiki-reader.native+18−1
@@ -173,4 +173,21 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
173,RawBlock "mediawiki" "{{Welcome}}"
173,RawBlock "mediawiki" "{{Welcome}}"
174,RawBlock "mediawiki" "{{Foo:Bar}}"
174,RawBlock "mediawiki" "{{Foo:Bar}}"
175,RawBlock "mediawiki" "{{Thankyou|all your effort|Me}}"
175,RawBlock "mediawiki" "{{Thankyou|all your effort|Me}}"
176−,Para [Str "Written",Space,RawInline "mediawiki" "{{{date}}}",Space,Str "by",Space,RawInline "mediawiki" "{{{name}}}",Str "."]]
176+,Para [Str "Written",Space,RawInline "mediawiki" "{{{date}}}",Space,Str "by",Space,RawInline "mediawiki" "{{{name}}}",Str "."]
177+,Header 2 [Str "tables"]
178+,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
179+ [[]
180+ ,[]]
181+ [[[Para [Str "Orange"]]
182+ ,[Para [Str "Apple"]]]
183+ ,[[Para [Str "Bread"]]
184+ ,[Para [Str "Pie"]]]
185+ ,[[Para [Str "Butter"]]
186+ ,[Para [Str "Ice",Space,Str "cream"]]]]
187+,Table [Str "Food",Space,Str "complements"] [AlignDefault,AlignDefault] [0.0,0.0]
188+ [[Para [Str "Orange"]]
189+ ,[Para [Str "Apple"]]]
190+ [[[Para [Str "Bread"]]
191+ ,[Para [Str "Pie"]]]
192+ ,[[Para [Str "Butter"]]
193+ ,[Para [Str "Ice",Space,Str "cream"]]]]]
tests/mediawiki-reader.wiki+26
@@ -281,3 +281,29 @@ Not<hr/> preformatted
281
281
282Written {{{date}}} by {{{name}}}.
282Written {{{date}}} by {{{name}}}.
283
283
284+== tables ==
285+
286+{|
287+|-
288+|Orange
289+|Apple
290+|-
291+|Bread
292+|Pie
293+|-
294+|Butter
295+|Ice cream
296+|}
297+
298+{|
299+|+Food complements
300+!Orange
301+!Apple
302+|-
303+|Bread
304+|Pie
305+|-
306+!Butter
307+|Ice cream
308+|}
309+