diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index d18a98bc0..89564f504 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -164,6 +164,9 @@ para = B.para . trimInlines . mconcat <$> many1 inline table :: MWParser Blocks table = do tableStart + styles <- manyTill anyChar newline + let tableWidth = maybe (1.0 :: Double) read + $ lookup "width" $ parseAttrs styles caption <- option mempty tableCaption optional rowsep hasheader <- option False $ True <$ (lookAhead (char '!')) @@ -178,8 +181,22 @@ table = do let cellspecs = replicate cols (AlignDefault, 0.0) return $ B.table caption cellspecs headers rows +parseAttrs :: String -> [(String,String)] +parseAttrs s = case parse (many parseAttr) "attributes" s of + Right r -> r + Left _ -> [] + +parseAttr :: Parser String () (String, String) +parseAttr = try $ do + skipMany spaceChar + k <- many1 letter + char '=' + char '"' + v <- many1Till anyChar (char '"') + return (k,v) + tableStart :: MWParser () -tableStart = try $ guardColumnOne *> sym "{|" <* blanklines +tableStart = try $ guardColumnOne *> sym "{|" tableEnd :: MWParser () tableEnd = try $ guardColumnOne *> sym "|}" <* blanklines diff --git a/tests/mediawiki-reader.native b/tests/mediawiki-reader.native index 6e19c14ce..9954481fd 100644 --- a/tests/mediawiki-reader.native +++ b/tests/mediawiki-reader.native @@ -199,4 +199,17 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []}) ,[Para [Str "Pie"] ,OrderedList (1,DefaultStyle,DefaultDelim) [[Plain [Str "apple"]] - ,[Plain [Str "carrot"]]]]]]] + ,[Plain [Str "carrot"]]]]]] +,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0] + [[] + ,[] + ,[]] + [[[Para [Str "Orange"]] + ,[Para [Str "Apple"]] + ,[Para [Str "more"]]] + ,[[Para [Str "Bread"]] + ,[Para [Str "Pie"]] + ,[Para [Str "more"]]] + ,[[Para [Str "Butter"]] + ,[Para [Str "Ice",Space,Str "cream"]] + ,[Para [Str "and",Space,Str "more"]]]]] diff --git a/tests/mediawiki-reader.wiki b/tests/mediawiki-reader.wiki index b2bfb47e8..fd1159cd4 100644 --- a/tests/mediawiki-reader.wiki +++ b/tests/mediawiki-reader.wiki @@ -322,5 +322,11 @@ and cheese |} - +{| +| Orange || Apple || more +|- +| Bread || Pie || more +|- +| Butter || Ice cream || and more +|}