aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-14 10:55:16 -0400
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-14 10:55:16 -0400
commitce509be57a1209367d71a4cd5959f0478a5b2294 (patch)
treee558b1a0146f3f7314377c7c0c7afdc69c198dde
parent6e9351bac4f2ed54286d568adeb6454407bbff81 (diff)
downloadpandoc-ce509be57a1209367d71a4cd5959f0478a5b2294.tar.gz
MediaWiki reader: Table improvements, added simple table tests.
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs13
-rw-r--r--tests/mediawiki-reader.native19
-rw-r--r--tests/mediawiki-reader.wiki26
3 files changed, 53 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index 85001904c..9f78146f8 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -171,7 +171,7 @@ table = do
rows' <- many $ try $ rowsep *> tableRow
tableEnd
-- TODO handle cellspecs from styles and aligns...
- let cols = length $ head rows'
+ let cols = length hdr
let (headers,rows) = if hasheader
then (hdr, rows')
else (replicate cols mempty, hdr:rows')
@@ -197,11 +197,12 @@ tableCaption = try $ guardColumnOne *> sym "|+" *> skipMany spaceChar *>
(trimInlines . mconcat <$> (many inline)) <* skipMany blankline
tableRow :: MWParser [Blocks]
-tableRow = try $ many tableCell <* skipMany blankline
+tableRow = try $ many tableCell
tableCell :: MWParser Blocks
tableCell =
- try $ cellsep *> skipMany spaceChar *> (mconcat <$> (many block))
+ try $ cellsep *> skipMany spaceChar *>
+ (mconcat <$> (many $ notFollowedBy (cellsep <|> rowsep <|> tableEnd) *> block))
template :: MWParser Blocks
template = B.rawBlock "mediawiki" <$> doublebrackets
@@ -405,7 +406,9 @@ inlineTag = do
special :: MWParser Inlines
special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
- notFollowedBy (char '|') *> oneOf specialChars)
+-- notFollowedBy (tableStart <|> tableEnd
+-- <|> cellsep <|> rowsep) *>
+ oneOf specialChars)
inlineHtml :: MWParser Inlines
inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
@@ -418,8 +421,10 @@ endline = () <$ try (newline <*
notFollowedBy blankline <*
notFollowedBy' hrule <*
notFollowedBy tableStart <*
+ notFollowedBy tableEnd <*
notFollowedBy' template <*
notFollowedBy cellsep <*
+ notFollowedBy rowsep <*
notFollowedBy anyListStart)
image :: MWParser Inlines
diff --git a/tests/mediawiki-reader.native b/tests/mediawiki-reader.native
index 2e8c9fdec..8b608fb17 100644
--- a/tests/mediawiki-reader.native
+++ b/tests/mediawiki-reader.native
@@ -173,4 +173,21 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
,RawBlock "mediawiki" "{{Welcome}}"
,RawBlock "mediawiki" "{{Foo:Bar}}"
,RawBlock "mediawiki" "{{Thankyou|all your effort|Me}}"
-,Para [Str "Written",Space,RawInline "mediawiki" "{{{date}}}",Space,Str "by",Space,RawInline "mediawiki" "{{{name}}}",Str "."]]
+,Para [Str "Written",Space,RawInline "mediawiki" "{{{date}}}",Space,Str "by",Space,RawInline "mediawiki" "{{{name}}}",Str "."]
+,Header 2 [Str "tables"]
+,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
+ [[]
+ ,[]]
+ [[[Para [Str "Orange"]]
+ ,[Para [Str "Apple"]]]
+ ,[[Para [Str "Bread"]]
+ ,[Para [Str "Pie"]]]
+ ,[[Para [Str "Butter"]]
+ ,[Para [Str "Ice",Space,Str "cream"]]]]
+,Table [Str "Food",Space,Str "complements"] [AlignDefault,AlignDefault] [0.0,0.0]
+ [[Para [Str "Orange"]]
+ ,[Para [Str "Apple"]]]
+ [[[Para [Str "Bread"]]
+ ,[Para [Str "Pie"]]]
+ ,[[Para [Str "Butter"]]
+ ,[Para [Str "Ice",Space,Str "cream"]]]]]
diff --git a/tests/mediawiki-reader.wiki b/tests/mediawiki-reader.wiki
index 50b315d71..655c8313e 100644
--- a/tests/mediawiki-reader.wiki
+++ b/tests/mediawiki-reader.wiki
@@ -281,3 +281,29 @@ Not<hr/> preformatted
Written {{{date}}} by {{{name}}}.
+== tables ==
+
+{|
+|-
+|Orange
+|Apple
+|-
+|Bread
+|Pie
+|-
+|Butter
+|Ice cream
+|}
+
+{|
+|+Food complements
+!Orange
+!Apple
+|-
+|Bread
+|Pie
+|-
+!Butter
+|Ice cream
+|}
+