diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-05-09 10:34:37 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-05-09 10:34:37 -0700 |
commit | 87de361cdc165e4c31ddde0287635ef54ac409a8 (patch) | |
tree | 1f6439c6a5e8bcabce50eb4de4b6d12eb28c7770 /src/Text | |
parent | fb62e0937c29c4a91cfd0fbcb688f62023da6eee (diff) | |
download | pandoc-87de361cdc165e4c31ddde0287635ef54ac409a8.tar.gz |
DocBook reader: More improvements, passes tests.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index ba2b79049..dcdd2de56 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -89,7 +89,7 @@ List of all DocBook tags, with [x] indicating implemented, [ ] collab - Identifies a collaborator [ ] collabname - The name of a collaborator [ ] colophon - Text at the back of a book describing facts about its production -[ ] colspec - Specifications for a column in a table +[x] colspec - Specifications for a column in a table [ ] command - The name of an executable program or other software command [ ] computeroutput - Data, generally text, displayed or presented by a computer [ ] confdates - The dates of a conference for which a document was written @@ -570,7 +570,8 @@ getImage e = do Just z -> case filterChild (named "imagedata") z of Nothing -> return mempty Just i -> return $ attrValue "fileref" i - caption <- case filterChild (named "caption") e of + caption <- case filterChild + (\x -> named "caption" x || named "textobject" x) e of Nothing -> return mempty Just z -> mconcat <$> (mapM parseInline $ elContent z) return $ image imageUrl "" caption @@ -709,15 +710,26 @@ parseBlock (Elem e) = Just "right" -> AlignRight Just "center" -> AlignCenter _ -> AlignDefault + let toWidth c = case findAttr (unqual "colwidth") c of + Just w -> read $ filter (\x -> + (x >= '0' && x <= '9') + || x == '.') w + Nothing -> 0 :: Double let numrows = maximum $ map length bodyrows let aligns = case colspecs of [] -> replicate numrows AlignDefault cs -> map toAlignment cs + let widths = case colspecs of + [] -> replicate numrows 0 + cs -> let ws = map toWidth cs + tot = sum ws + in if all (> 0) ws + then map (/ tot) ws + else replicate numrows 0 let headrows' = if null headrows then replicate numrows mempty else headrows - return $ table caption - (zip aligns (repeat 0)) + return $ table caption (zip aligns widths) headrows' bodyrows isEntry x = named "entry" x || named "td" x || named "th" x parseRow = mapM getBlocks . filterChildren isEntry |