aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-05-09 10:34:37 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-05-09 10:34:37 -0700
commit87de361cdc165e4c31ddde0287635ef54ac409a8 (patch)
tree1f6439c6a5e8bcabce50eb4de4b6d12eb28c7770
parentfb62e0937c29c4a91cfd0fbcb688f62023da6eee (diff)
downloadpandoc-87de361cdc165e4c31ddde0287635ef54ac409a8.tar.gz
DocBook reader: More improvements, passes tests.
-rw-r--r--src/Text/Pandoc/Readers/DocBook.hs20
-rw-r--r--tests/docbook-reader.docbook24
-rw-r--r--tests/docbook-reader.native8
3 files changed, 32 insertions, 20 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
diff --git a/tests/docbook-reader.docbook b/tests/docbook-reader.docbook
index 1b195602d..eb70dd33c 100644
--- a/tests/docbook-reader.docbook
+++ b/tests/docbook-reader.docbook
@@ -1259,10 +1259,10 @@ or here: &lt;http://example.com/&gt;
Here's the caption. It may span multiple lines.
</title>
<tgroup cols="4">
- <colspec colwidth="15*" align="center" />
- <colspec colwidth="13*" align="left" />
- <colspec colwidth="16*" align="right" />
- <colspec colwidth="33*" align="left" />
+ <colspec colwidth="2*" align="center" />
+ <colspec colwidth="2*" align="left" />
+ <colspec colwidth="3*" align="right" />
+ <colspec colwidth="3*" align="left" />
<thead>
<row>
<entry>
@@ -1316,10 +1316,10 @@ or here: &lt;http://example.com/&gt;
</para>
<informaltable>
<tgroup cols="4">
- <colspec colwidth="15*" align="center" />
- <colspec colwidth="13*" align="left" />
- <colspec colwidth="16*" align="right" />
- <colspec colwidth="33*" align="left" />
+ <colspec colwidth="1*" align="center" />
+ <colspec colwidth="2*" align="left" />
+ <colspec colwidth="3*" align="right" />
+ <colspec colwidth="4*" align="left" />
<thead>
<row>
<entry>
@@ -1428,10 +1428,10 @@ or here: &lt;http://example.com/&gt;
</para>
<informaltable>
<tgroup cols="4">
- <colspec colwidth="15*" align="center" />
- <colspec colwidth="13*" align="left" />
- <colspec colwidth="16*" align="right" />
- <colspec colwidth="33*" align="left" />
+ <colspec colwidth="10*" align="center" />
+ <colspec colwidth="10*" align="left" />
+ <colspec colwidth="10*" align="right" />
+ <colspec colwidth="10*" align="left" />
<tbody>
<row>
<entry>
diff --git a/tests/docbook-reader.native b/tests/docbook-reader.native
index aa459eff7..3d403648b 100644
--- a/tests/docbook-reader.native
+++ b/tests/docbook-reader.native
@@ -261,7 +261,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
,Header 1 [Str "Images"]
,Para [Str "From",Space,Quoted DoubleQuote [Str "Voyage",Space,Str "dans",Space,Str "la",Space,Str "Lune"],Space,Str "by",Space,Str "Georges",Space,Str "Melies",Space,Str "(1902):"]
,Para [Image [Str "lalune"] ("lalune.jpg","")]
-,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [Str "movie"] ("movie.jpg",""),Space,Str "icon."]
+,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [] ("movie.jpg",""),Space,Str "icon."]
,Header 1 [Str "Footnotes"]
,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "footnote",Space,Str "reference,",Note [Para [Str "Here",Space,Str "is",Space,Str "the",Space,Str "footnote.",Space,Str "It",Space,Str "can",Space,Str "go",Space,Str "anywhere",Space,Str "after",Space,Str "the",Space,Str "footnote",Space,Str "reference.",Space,Str "It",Space,Str "need",Space,Str "not",Space,Str "be",Space,Str "placed",Space,Str "at",Space,Str "the",Space,Str "end",Space,Str "of",Space,Str "the",Space,Str "document."]],Space,Str "and",Space,Str "another.",Note [Para [Str "Here\8217s",Space,Str "the",Space,Str "long",Space,Str "note.",Space,Str "This",Space,Str "one",Space,Str "contains",Space,Str "multiple",Space,Str "blocks."],Para [Str "Subsequent",Space,Str "blocks",Space,Str "are",Space,Str "indented",Space,Str "to",Space,Str "show",Space,Str "that",Space,Str "they",Space,Str "belong",Space,Str "to",Space,Str "the",Space,Str "footnote",Space,Str "(as",Space,Str "with",Space,Str "list",Space,Str "items)."],CodeBlock ("",[],[]) " { <code> }",Para [Str "If",Space,Str "you",Space,Str "want,",Space,Str "you",Space,Str "can",Space,Str "indent",Space,Str "every",Space,Str "line,",Space,Str "but",Space,Str "you",Space,Str "can",Space,Str "also",Space,Str "be",Space,Str "lazy",Space,Str "and",Space,Str "just",Space,Str "indent",Space,Str "the",Space,Str "first",Space,Str "line",Space,Str "of",Space,Str "each",Space,Str "block."]],Space,Str "This",Space,Str "should",Space,Emph [Str "not"],Space,Str "be",Space,Str "a",Space,Str "footnote",Space,Str "reference,",Space,Str "because",Space,Str "it",Space,Str "contains",Space,Str "a",Space,Str "space.[^my",Space,Str "note]",Space,Str "Here",Space,Str "is",Space,Str "an",Space,Str "inline",Space,Str "note.",Note [Para [Str "This",Space,Str "is",Space,Emph [Str "easier"],Space,Str "to",Space,Str "type.",Space,Str "Inline",Space,Str "notes",Space,Str "may",Space,Str "contain",Space,Link [Str "links"] ("http://google.com",""),Space,Str "and",Space,Code ("",[],[]) "]",Space,Str "verbatim",Space,Str "characters,",Space,Str "as",Space,Str "well",Space,Str "as",Space,Str "[bracketed",Space,Str "text]."]]]
,BlockQuote
@@ -325,7 +325,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
,[Plain [Str "1"]]
,[Plain [Str "1"]]]]
,Para [Str "Multiline",Space,Str "table",Space,Str "with",Space,Str "caption:"]
-,Table [Str "Here's",Space,Str "the",Space,Str "caption.",Space,Str "It",Space,Str "may",Space,Str "span",Space,Str "multiple",Space,Str "lines."] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.15,0.1375,0.1625,0.3375]
+,Table [Str "Here's",Space,Str "the",Space,Str "caption.",Space,Str "It",Space,Str "may",Space,Str "span",Space,Str "multiple",Space,Str "lines."] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.2,0.2,0.3,0.3]
[[Plain [Str "Centered",Space,Str "Header"]]
,[Plain [Str "Left",Space,Str "Aligned"]]
,[Plain [Str "Right",Space,Str "Aligned"]]
@@ -339,7 +339,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
,[Plain [Str "5.0"]]
,[Plain [Str "Here's",Space,Str "another",Space,Str "one.",Space,Str "Note",Space,Str "the",Space,Str "blank",Space,Str "line",Space,Str "between",Space,Str "rows."]]]]
,Para [Str "Multiline",Space,Str "table",Space,Str "without",Space,Str "caption:"]
-,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.15,0.1375,0.1625,0.3375]
+,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.1,0.2,0.3,0.4]
[[Plain [Str "Centered",Space,Str "Header"]]
,[Plain [Str "Left",Space,Str "Aligned"]]
,[Plain [Str "Right",Space,Str "Aligned"]]
@@ -371,7 +371,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
,[Plain [Str "1"]]
,[Plain [Str "1"]]]]
,Para [Str "Multiline",Space,Str "table",Space,Str "without",Space,Str "column",Space,Str "headers:"]
-,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.15,0.1375,0.1625,0.3375]
+,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.25,0.25,0.25,0.25]
[[]
,[]
,[]