Skip to content

Commit

Permalink
Improved reading <xref> elements in DocBook files (#8065)
Browse files Browse the repository at this point in the history
<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.
  • Loading branch information
frerich authored May 12, 2022
1 parent b0195b7 commit b888a8c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Text/Pandoc/Readers/DocBook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion test/docbook-xref.docbook
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>

40 changes: 40 additions & 0 deletions test/docbook-xref.native
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:" )
]
]

0 comments on commit b888a8c

Please sign in to comment.