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 /src/Text/Pandoc | |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 18 |
1 files changed, 12 insertions, 6 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 |