git.iko.soy/typeable/pandoc
on master help sign in
DocBook reader: More improvements, passes tests.
commit87de361cdc165e4c31ddde0287635ef54ac409a8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 9 May 2012, 10:34 (14 years ago) parentfb62e09
3 files changed+32−20
src/Text/Pandoc/Readers/DocBook.hs+16−4 tests/docbook-reader.docbook+12−12 tests/docbook-reader.native+4−4
src/Text/Pandoc/Readers/DocBook.hs+16−4
@@ -89,7 +89,7 @@ List of all DocBook tags, with [x] indicating implemented,
8989[ ] collab - Identifies a collaborator
9090[ ] collabname - The name of a collaborator
9191[ ] colophon - Text at the back of a book describing facts about its production
92−[ ] colspec - Specifications for a column in a table
92+[x] colspec - Specifications for a column in a table
9393[ ] command - The name of an executable program or other software command
9494[ ] computeroutput - Data, generally text, displayed or presented by a computer
9595[ ] confdates - The dates of a conference for which a document was written
@@ -570,7 +570,8 @@ getImage e = do
570570 Just z -> case filterChild (named "imagedata") z of
571571 Nothing -> return mempty
572572 Just i -> return $ attrValue "fileref" i
573− caption <- case filterChild (named "caption") e of
573+ caption <- case filterChild
574+ (\x -> named "caption" x || named "textobject" x) e of
574575 Nothing -> return mempty
575576 Just z -> mconcat <$> (mapM parseInline $ elContent z)
576577 return $ image imageUrl "" caption
@@ -709,15 +710,26 @@ parseBlock (Elem e) =
709710 Just "right" -> AlignRight
710711 Just "center" -> AlignCenter
711712 _ -> AlignDefault
713+ let toWidth c = case findAttr (unqual "colwidth") c of
714+ Just w -> read $ filter (\x ->
715+ (x >= '0' && x <= '9')
716+ || x == '.') w
717+ Nothing -> 0 :: Double
712718 let numrows = maximum $ map length bodyrows
713719 let aligns = case colspecs of
714720 [] -> replicate numrows AlignDefault
715721 cs -> map toAlignment cs
722+ let widths = case colspecs of
723+ [] -> replicate numrows 0
724+ cs -> let ws = map toWidth cs
725+ tot = sum ws
726+ in if all (> 0) ws
727+ then map (/ tot) ws
728+ else replicate numrows 0
716729 let headrows' = if null headrows
717730 then replicate numrows mempty
718731 else headrows
719− return $ table caption
720− (zip aligns (repeat 0))
732+ return $ table caption (zip aligns widths)
721733 headrows' bodyrows
722734 isEntry x = named "entry" x || named "td" x || named "th" x
723735 parseRow = mapM getBlocks . filterChildren isEntry
tests/docbook-reader.docbook+12−12
@@ -1259,10 +1259,10 @@ or here: &lt;http://example.com/&gt;
12591259 Here's the caption. It may span multiple lines.
12601260 </title>
12611261 <tgroup cols="4">
1262− <colspec colwidth="15*" align="center" />
1263− <colspec colwidth="13*" align="left" />
1264− <colspec colwidth="16*" align="right" />
1265− <colspec colwidth="33*" align="left" />
1262+ <colspec colwidth="2*" align="center" />
1263+ <colspec colwidth="2*" align="left" />
1264+ <colspec colwidth="3*" align="right" />
1265+ <colspec colwidth="3*" align="left" />
12661266 <thead>
12671267 <row>
12681268 <entry>
@@ -1316,10 +1316,10 @@ or here: &lt;http://example.com/&gt;
13161316 </para>
13171317 <informaltable>
13181318 <tgroup cols="4">
1319− <colspec colwidth="15*" align="center" />
1320− <colspec colwidth="13*" align="left" />
1321− <colspec colwidth="16*" align="right" />
1322− <colspec colwidth="33*" align="left" />
1319+ <colspec colwidth="1*" align="center" />
1320+ <colspec colwidth="2*" align="left" />
1321+ <colspec colwidth="3*" align="right" />
1322+ <colspec colwidth="4*" align="left" />
13231323 <thead>
13241324 <row>
13251325 <entry>
@@ -1428,10 +1428,10 @@ or here: &lt;http://example.com/&gt;
14281428 </para>
14291429 <informaltable>
14301430 <tgroup cols="4">
1431− <colspec colwidth="15*" align="center" />
1432− <colspec colwidth="13*" align="left" />
1433− <colspec colwidth="16*" align="right" />
1434− <colspec colwidth="33*" align="left" />
1431+ <colspec colwidth="10*" align="center" />
1432+ <colspec colwidth="10*" align="left" />
1433+ <colspec colwidth="10*" align="right" />
1434+ <colspec colwidth="10*" align="left" />
14351435 <tbody>
14361436 <row>
14371437 <entry>
tests/docbook-reader.native+4−4
@@ -261,7 +261,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
261261,Header 1 [Str "Images"]
262262,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):"]
263263,Para [Image [Str "lalune"] ("lalune.jpg","")]
264−,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [Str "movie"] ("movie.jpg",""),Space,Str "icon."]
264+,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [] ("movie.jpg",""),Space,Str "icon."]
265265,Header 1 [Str "Footnotes"]
266266,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]."]]]
267267,BlockQuote
@@ -325,7 +325,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
325325 ,[Plain [Str "1"]]
326326 ,[Plain [Str "1"]]]]
327327,Para [Str "Multiline",Space,Str "table",Space,Str "with",Space,Str "caption:"]
328−,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]
328+,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]
329329 [[Plain [Str "Centered",Space,Str "Header"]]
330330 ,[Plain [Str "Left",Space,Str "Aligned"]]
331331 ,[Plain [Str "Right",Space,Str "Aligned"]]
@@ -339,7 +339,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
339339 ,[Plain [Str "5.0"]]
340340 ,[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."]]]]
341341,Para [Str "Multiline",Space,Str "table",Space,Str "without",Space,Str "caption:"]
342−,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.15,0.1375,0.1625,0.3375]
342+,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.1,0.2,0.3,0.4]
343343 [[Plain [Str "Centered",Space,Str "Header"]]
344344 ,[Plain [Str "Left",Space,Str "Aligned"]]
345345 ,[Plain [Str "Right",Space,Str "Aligned"]]
@@ -371,7 +371,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
371371 ,[Plain [Str "1"]]
372372 ,[Plain [Str "1"]]]]
373373,Para [Str "Multiline",Space,Str "table",Space,Str "without",Space,Str "column",Space,Str "headers:"]
374−,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.15,0.1375,0.1625,0.3375]
374+,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.25,0.25,0.25,0.25]
375375 [[]
376376 ,[]
377377 ,[]