git.iko.soy/typeable/pandoc
on master help sign in
DocBook reader mediaobjects and figures, closes #2184
commit82e363a727456deb3f32d1683defee0fd8bbd32c authormb21 <mb21@users.noreply.github.com> dateSun 21 Jun 2015, 16:24 (11 years ago) parent3202287
3 files changed+43−15
src/Text/Pandoc/Readers/DocBook.hs+20−11 tests/docbook-reader.docbook+20−2 tests/docbook-reader.native+3−2
src/Text/Pandoc/Readers/DocBook.hs+20−11
@@ -167,7 +167,9 @@ List of all DocBook tags, with [x] indicating implemented,
167167[x] glossseealso - A cross-reference from one GlossEntry to another
168168[x] glossterm - A glossary term
169169[ ] graphic - A displayed graphical object (not an inline)
170+ Note: in DocBook v5 `graphic` is discarded
170171[ ] graphicco - A graphic that contains callout areas
172+ Note: in DocBook v5 `graphicco` is discarded
171173[ ] group - A group of elements in a CmdSynopsis
172174[ ] guibutton - The text on a button in a GUI
173175[ ] guiicon - Graphic and/or text appearing as a icon in a GUI
@@ -180,8 +182,9 @@ List of all DocBook tags, with [x] indicating implemented,
180182[ ] holder - The name of the individual or organization that holds a copyright
181183[o] honorific - The title of a person
182184[ ] html:form - An HTML form
183−[ ] imagedata - Pointer to external image data
184−[ ] imageobject - A wrapper for image data and its associated meta-information
185+[x] imagedata - Pointer to external image data (only `fileref` attribute
186+ implemented but not `entityref` which would require parsing of the DTD)
187+[x] imageobject - A wrapper for image data and its associated meta-information
185188[ ] imageobjectco - A wrapper for an image object with callouts
186189[x] important - An admonition set off from the text
187190[x] index - An index
@@ -627,18 +630,24 @@ addToStart toadd bs =
627630
628631-- function that is used by both mediaobject (in parseBlock)
629632-- and inlinemediaobject (in parseInline)
630−getImage :: Element -> DB Inlines
631−getImage e = do
633+-- A DocBook mediaobject is a wrapper around a set of alternative presentations
634+getMediaobject :: Element -> DB Inlines
635+getMediaobject e = do
632636 imageUrl <- case filterChild (named "imageobject") e of
633637 Nothing -> return mempty
634638 Just z -> case filterChild (named "imagedata") z of
635639 Nothing -> return mempty
636640 Just i -> return $ attrValue "fileref" i
637− caption <- case filterChild
638− (\x -> named "caption" x || named "textobject" x) e of
639− Nothing -> gets dbFigureTitle
640− Just z -> mconcat <$> (mapM parseInline $ elContent z)
641− return $ image imageUrl "" caption
641+ let getCaption el = case filterChild (\x -> named "caption" x
642+ || named "textobject" x
643+ || named "alt" x) el of
644+ Nothing -> return mempty
645+ Just z -> mconcat <$> (mapM parseInline $ elContent z)
646+ figTitle <- gets dbFigureTitle
647+ let (caption, title) = if isNull figTitle
648+ then (getCaption e, "")
649+ else (return figTitle, "fig:")
650+ liftM (image imageUrl title) caption
642651
643652getBlocks :: Element -> DB Blocks
644653getBlocks e = mconcat <$> (mapM parseBlock $ elContent e)
@@ -734,7 +743,7 @@ parseBlock (Elem e) =
734743 <$> listitems
735744 "variablelist" -> definitionList <$> deflistitems
736745 "figure" -> getFigure e
737− "mediaobject" -> para <$> getImage e
746+ "mediaobject" -> para <$> getMediaobject e
738747 "caption" -> return mempty
739748 "info" -> metaBlock
740749 "articleinfo" -> metaBlock
@@ -902,7 +911,7 @@ parseInline (Elem e) =
902911 "inlineequation" -> equation math
903912 "subscript" -> subscript <$> innerInlines
904913 "superscript" -> superscript <$> innerInlines
905− "inlinemediaobject" -> getImage e
914+ "inlinemediaobject" -> getMediaobject e
906915 "quote" -> do
907916 qt <- gets dbQuoteType
908917 let qt' = if qt == SingleQuote then DoubleQuote else SingleQuote
tests/docbook-reader.docbook+20−2
@@ -1033,12 +1033,12 @@ or here: &lt;http://example.com/&gt;
10331033 From <quote>Voyage dans la Lune</quote> by Georges Melies (1902):
10341034 </para>
10351035 <figure>
1036− <title>lalune</title>
1036+ <title>lalune fig caption</title>
10371037 <mediaobject>
10381038 <imageobject>
10391039 <imagedata fileref="lalune.jpg" />
10401040 </imageobject>
1041− <textobject><phrase>lalune</phrase></textobject>
1041+ <textobject><phrase>lalune alt text shadowed by fig caption</phrase></textobject>
10421042 </mediaobject>
10431043 </figure>
10441044 <para>
@@ -1047,7 +1047,25 @@ or here: &lt;http://example.com/&gt;
10471047 <imagedata fileref="movie.jpg" />
10481048 </imageobject>
10491049 </inlinemediaobject> icon.
1050+ And here a second movie <inlinemediaobject>
1051+ <alt>alt text</alt>
1052+ <imageobject>
1053+ <imagedata fileref="movie.jpg" />
1054+ </imageobject>
1055+ </inlinemediaobject> icon.
1056+ And here a third movie <inlinemediaobject>
1057+ <textobject><phrase>alt text</phrase></textobject>
1058+ <imageobject>
1059+ <imagedata fileref="movie.jpg" />
1060+ </imageobject>
1061+ </inlinemediaobject> icon.
10501062 </para>
1063+ <mediaobject>
1064+ <imageobject>
1065+ <imagedata fileref="lalune.jpg" />
1066+ </imageobject>
1067+ <textobject><phrase>lalune no figure alt text</phrase></textobject>
1068+ </mediaobject>
10511069</sect1>
10521070<sect1 id="footnotes">
10531071 <title>Footnotes</title>
tests/docbook-reader.native+3−2
@@ -270,8 +270,9 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
270270,CodeBlock ("",[],[]) "or here: <http://example.com/>"
271271,Header 1 ("images",[],[]) [Str "Images"]
272272,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):"]
273−,Para [Image [Str "lalune"] ("lalune.jpg","")]
274−,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [] ("movie.jpg",""),Space,Str "icon."]
273+,Para [Image [Str "lalune",Space,Str "fig",Space,Str "caption"] ("lalune.jpg","fig:")]
274+,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [] ("movie.jpg",""),Space,Str "icon.",Space,Str "And",Space,Str "here",Space,Str "a",Space,Str "second",Space,Str "movie",Space,Image [Str "alt",Space,Str "text"] ("movie.jpg",""),Space,Str "icon.",Space,Str "And",Space,Str "here",Space,Str "a",Space,Str "third",Space,Str "movie",Space,Image [Str "alt",Space,Str "text"] ("movie.jpg",""),Space,Str "icon."]
275+,Para [Image [Str "lalune",Space,Str "no",Space,Str "figure",Space,Str "alt",Space,Str "text"] ("lalune.jpg","")]
275276,Header 1 ("footnotes",[],[]) [Str "Footnotes"]
276277,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]."]]]
277278,BlockQuote