diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-09-15 14:20:50 -0400 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-09-15 14:20:50 -0400 |
commit | 26fb63e2946da932662127bddde5005048f10855 (patch) | |
tree | f22c605e3746b8d1f236bbd89a58b5183d49dcb4 | |
parent | eca9eeab6bcb5b36f40ca54659bb22658cecad30 (diff) | |
download | pandoc-26fb63e2946da932662127bddde5005048f10855.tar.gz |
MediaWiki reader: Got alignments working.
They only work on headers, because pandoc forces same
alignment for all cells in a column.
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 18 | ||||
-rw-r--r-- | tests/mediawiki-reader.native | 12 | ||||
-rw-r--r-- | tests/mediawiki-reader.wiki | 10 |
3 files changed, 33 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 751326bb6..0c2566faf 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -190,15 +190,15 @@ table = do caption <- option mempty tableCaption optional rowsep hasheader <- option False $ True <$ (lookAhead (char '!')) - hdr <- tableRow - rows' <- many $ try $ rowsep *> tableRow + (aligns,hdr) <- unzip <$> tableRow + rows' <- many $ try $ rowsep *> (map snd <$> tableRow) tableEnd -- TODO handle cellspecs from styles and aligns... let cols = length hdr let (headers,rows) = if hasheader then (hdr, rows') else (replicate cols mempty, hdr:rows') - let cellspecs = replicate cols (AlignDefault, 0.0) + let cellspecs = zip aligns (repeat 0.0) return $ B.table caption cellspecs headers rows parseAttrs :: String -> [(String,String)] @@ -238,10 +238,10 @@ tableCaption = try $ do res <- manyTill anyChar newline >>= parseFromString (many inline) return $ trimInlines $ mconcat res -tableRow :: MWParser [Blocks] +tableRow :: MWParser [(Alignment, Blocks)] tableRow = try $ many tableCell -tableCell :: MWParser Blocks +tableCell :: MWParser (Alignment, Blocks) tableCell = try $ do cellsep skipMany spaceChar @@ -249,7 +249,13 @@ tableCell = try $ do manyTill (satisfy (/='\n')) (char '|' <* notFollowedBy (char '|')) skipMany spaceChar ls <- many (notFollowedBy (cellsep <|> rowsep <|> tableEnd) *> anyChar) - parseFromString (mconcat <$> many block) ls + bs <- parseFromString (mconcat <$> many block) ls + let align = case lookup "align" attrs of + Just "left" -> AlignLeft + Just "right" -> AlignRight + Just "center" -> AlignCenter + _ -> AlignDefault + return (align, bs) template :: MWParser String template = try $ do diff --git a/tests/mediawiki-reader.native b/tests/mediawiki-reader.native index 25c0eaa72..3ca7b6b79 100644 --- a/tests/mediawiki-reader.native +++ b/tests/mediawiki-reader.native @@ -213,4 +213,14 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []}) ,[Para [Str "more"]]] ,[[Para [Str "Butter"]] ,[Para [Str "Ice",Space,Str "cream"]] - ,[Para [Str "and",Space,Str "more"]]]]] + ,[Para [Str "and",Space,Str "more"]]]] +,Table [] [AlignLeft,AlignRight,AlignCenter] [0.0,0.0,0.0] + [[Para [Str "Left"]] + ,[Para [Str "Right"]] + ,[Para [Str "Center"]]] + [[[Para [Str "left"]] + ,[Para [Str "15.00"]] + ,[Para [Str "centered"]]] + ,[[Para [Str "more"]] + ,[Para [Str "2.0"]] + ,[Para [Str "more"]]]]] diff --git a/tests/mediawiki-reader.wiki b/tests/mediawiki-reader.wiki index 154248e54..10deebec8 100644 --- a/tests/mediawiki-reader.wiki +++ b/tests/mediawiki-reader.wiki @@ -330,3 +330,13 @@ and cheese | Butter || Ice cream || and more |} +{| +! align="left"| Left +! align="right"|Right +! align="center"|Center +|- +| left || 15.00 || centered +|- +| more || 2.0 || more +|} + |