diff options
| author | Frerich Raabe <frerich.raabe@betterdoc.de> | 2022-05-12 04:07:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-11 19:07:03 -0700 |
| commit | b888a8c77e35cc028725aff0f581475ec0481af9 (patch) | |
| tree | 89fedb6f9d0ad8c05d235b1af475439f01e2acc2 | |
| parent | b0195b7ef4d55c1d7339cd77aa0e3a039a095807 (diff) | |
Improved reading <xref> elements in DocBook files (#8065)
<xref> elements can also be used to link to <figure> elements. Alas, the
DocBook reader was not aware of this and thus generated a link text
which just said 'figure_title'.
https://tdg.docbook.org/tdg/4.5/figure.html explains that <figure>
elements can contain <title> elements, so let's try to use that if it is
available.
| -rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 1 | ||||
| -rw-r--r-- | test/docbook-xref.docbook | 13 | ||||
| -rw-r--r-- | test/docbook-xref.native | 40 |
3 files changed, 53 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 581a93e68..b7a2b06ea 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -1342,6 +1342,7 @@ parseInline (Elem e) = "sect5" -> descendantContent "title" el "cmdsynopsis" -> descendantContent "command" el "funcsynopsis" -> descendantContent "function" el + "figure" -> descendantContent "title" el _ -> qName (elName el) <> "_title" where xrefLabel = attrValue "xreflabel" el diff --git a/test/docbook-xref.docbook b/test/docbook-xref.docbook index ebcd94d00..a83657b6b 100644 --- a/test/docbook-xref.docbook +++ b/test/docbook-xref.docbook @@ -24,6 +24,9 @@ cross-reference text: <xref linkend="ch02"/>. <listitem><para>A link to an <sgmltag>funcsynopsis</sgmltag> element: <xref linkend="func01"/>. </para></listitem> +<listitem><para>A link to a +<sgmltag>figure</sgmltag> element: <xref linkend="fig01"/>. +</para></listitem> </itemizedlist> </chapter> @@ -65,6 +68,14 @@ cross-reference text: <xref linkend="ch02"/>. </funcprototype> </funcsynopsis> +<figure id="fig01"><title>The Pythagorean Theorem Illustrated</title> +<mediaobject> + <imageobject> + <imagedata fileref="figures/pythag.png"/> + </imageobject> + <textobject><phrase>An illustration of the Pythagorean Theorem</phrase></textobject> +</mediaobject> +</figure> + </chapter> </book> - diff --git a/test/docbook-xref.native b/test/docbook-xref.native index 2983eac0c..bcfe434a4 100644 --- a/test/docbook-xref.native +++ b/test/docbook-xref.native @@ -141,6 +141,33 @@ Pandoc , Str "." ] ] + , [ Para + [ Str "A" + , Space + , Str "link" + , Space + , Str "to" + , Space + , Str "a" + , SoftBreak + , Str "figure" + , Space + , Str "element:" + , Space + , Link + ( "" , [] , [] ) + [ Str "The" + , Space + , Str "Pythagorean" + , Space + , Str "Theorem" + , Space + , Str "Illustrated" + ] + ( "#fig01" , "" ) + , Str "." + ] + ] ] , Header 1 @@ -174,4 +201,17 @@ Pandoc , Plain [ Str "int1" ] , Plain [ Str "int" ] , Plain [ Str "int2" ] + , Para + [ Image + ( "fig01" , [] , [] ) + [ Str "The" + , Space + , Str "Pythagorean" + , Space + , Str "Theorem" + , Space + , Str "Illustrated" + ] + ( "figures/pythag.png" , "fig:" ) + ] ] |
