From b888a8c77e35cc028725aff0f581475ec0481af9 Mon Sep 17 00:00:00 2001 From: Frerich Raabe Date: Thu, 12 May 2022 04:07:03 +0200 Subject: [PATCH] Improved reading elements in DocBook files (#8065) elements can also be used to link to
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
elements can contain elements, so let's try to use that if it is available. --- src/Text/Pandoc/Readers/DocBook.hs | 1 + test/docbook-xref.docbook | 13 +++++++++- test/docbook-xref.native | 40 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) 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 + + + + + An illustration of the Pythagorean Theorem + +
+ - 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:" ) + ] ]