git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Table improvements, added simple table tests.
commitce509be57a1209367d71a4cd5959f0478a5b2294 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 14 Sep 2012, 10:55 (14 years ago) parent6e9351b
3 files changed+53−5
src/Text/Pandoc/Readers/MediaWiki.hs+9−4 tests/mediawiki-reader.native+18−1 tests/mediawiki-reader.wiki+26
src/Text/Pandoc/Readers/MediaWiki.hs+9−4
@@ -171,7 +171,7 @@ table = do
171171 rows' <- many $ try $ rowsep *> tableRow
172172 tableEnd
173173 -- TODO handle cellspecs from styles and aligns...
174− let cols = length $ head rows'
174+ let cols = length hdr
175175 let (headers,rows) = if hasheader
176176 then (hdr, rows')
177177 else (replicate cols mempty, hdr:rows')
@@ -197,11 +197,12 @@ tableCaption = try $ guardColumnOne *> sym "|+" *> skipMany spaceChar *>
197197 (trimInlines . mconcat <$> (many inline)) <* skipMany blankline
198198
199199tableRow :: MWParser [Blocks]
200−tableRow = try $ many tableCell <* skipMany blankline
200+tableRow = try $ many tableCell
201201
202202tableCell :: MWParser Blocks
203203tableCell =
204− try $ cellsep *> skipMany spaceChar *> (mconcat <$> (many block))
204+ try $ cellsep *> skipMany spaceChar *>
205+ (mconcat <$> (many $ notFollowedBy (cellsep <|> rowsep <|> tableEnd) *> block))
205206
206207template :: MWParser Blocks
207208template = B.rawBlock "mediawiki" <$> doublebrackets
@@ -405,7 +406,9 @@ inlineTag = do
405406
406407special :: MWParser Inlines
407408special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
408− notFollowedBy (char '|') *> oneOf specialChars)
409+-- notFollowedBy (tableStart <|> tableEnd
410+-- <|> cellsep <|> rowsep) *>
411+ oneOf specialChars)
409412
410413inlineHtml :: MWParser Inlines
411414inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
@@ -418,8 +421,10 @@ endline = () <$ try (newline <*
418421 notFollowedBy blankline <*
419422 notFollowedBy' hrule <*
420423 notFollowedBy tableStart <*
424+ notFollowedBy tableEnd <*
421425 notFollowedBy' template <*
422426 notFollowedBy cellsep <*
427+ notFollowedBy rowsep <*
423428 notFollowedBy anyListStart)
424429
425430image :: MWParser Inlines
tests/mediawiki-reader.native+18−1
@@ -173,4 +173,21 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
173173,RawBlock "mediawiki" "{{Welcome}}"
174174,RawBlock "mediawiki" "{{Foo:Bar}}"
175175,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
281281
282282Written {{{date}}} by {{{name}}}.
283283
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+