summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-03-21 20:47:45 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-03-22 08:32:48 -0700
commit821cf3df4df695d4bb8f8659a85993033939e860 (patch)
treea6c4165e2f7113252f5255f5adbbe28e408a2c85
parent440b438158e61b3452a9622112061430e457931b (diff)
DocBook reader: handle "book" for xref references
This also adds a test xref to book and part. See also 4ea0508e6 / #8712.
-rw-r--r--src/Text/Pandoc/Readers/DocBook.hs1
-rw-r--r--test/docbook-xref.docbook12
-rw-r--r--test/docbook-xref.native55
3 files changed, 64 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
index a0fdfa319..56fc0dc4c 100644
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -1354,6 +1354,7 @@ parseInline (Elem e) =
xrefTitleByElem el
| not (T.null xrefLabel) = xrefLabel
| otherwise = case qName (elName el) of
+ "book" -> descendantContent "title" el
"part" -> descendantContent "title" el
"chapter" -> descendantContent "title" el
"section" -> descendantContent "title" el
diff --git a/test/docbook-xref.docbook b/test/docbook-xref.docbook
index 624b4c081..87aaf86c6 100644
--- a/test/docbook-xref.docbook
+++ b/test/docbook-xref.docbook
@@ -1,6 +1,6 @@
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<book><title>An Example Book</title>
+<book id='book01'><title>An Example Book</title>
<chapter id="ch01"><title>XRef Samples</title>
<para>
This paragraph demonstrates several features of
@@ -30,6 +30,12 @@ cross-reference text: <xref linkend="ch02"/>.
<listitem><para>A link to a
<sgmltag>table</sgmltag> element: <xref linkend="table01"/>.
</para></listitem>
+<listitem><para>A link to a
+<sgmltag>part</sgmltag> element: <xref linkend="part01"/>.
+</para></listitem>
+<listitem><para>A link to a
+<sgmltag>book</sgmltag> element: <xref linkend="book01"/>.
+</para></listitem>
</itemizedlist>
</chapter>
@@ -38,6 +44,9 @@ cross-reference text: <xref linkend="ch02"/>.
<para>Some content here</para>
</chapter>
+<part id="part01">
+ <title>Later Part</title>
+
<chapter id="ch03" xreflabel="Chapter the Third">
<title>The Third Chapter</title>
<para>Some content here</para>
@@ -101,4 +110,5 @@ cross-reference text: <xref linkend="ch02"/>.
</table>
</chapter>
+</part>
</book>
diff --git a/test/docbook-xref.native b/test/docbook-xref.native
index 8025f698b..dedd7bfc5 100644
--- a/test/docbook-xref.native
+++ b/test/docbook-xref.native
@@ -14,7 +14,7 @@ Pandoc
]
}
[ Header
- 1
+ 2
( "ch01" , [] , [] )
[ Str "XRef" , Space , Str "Samples" ]
, Para
@@ -195,21 +195,70 @@ Pandoc
, Str "."
]
]
+ , [ Para
+ [ Str "A"
+ , Space
+ , Str "link"
+ , Space
+ , Str "to"
+ , Space
+ , Str "a"
+ , SoftBreak
+ , Str "part"
+ , Space
+ , Str "element:"
+ , Space
+ , Link
+ ( "" , [] , [] )
+ [ Str "Later" , Space , Str "Part" ]
+ ( "#part01" , "" )
+ , Str "."
+ ]
+ ]
+ , [ Para
+ [ Str "A"
+ , Space
+ , Str "link"
+ , Space
+ , Str "to"
+ , Space
+ , Str "a"
+ , SoftBreak
+ , Str "book"
+ , Space
+ , Str "element:"
+ , Space
+ , Link
+ ( "" , [] , [] )
+ [ Str "An"
+ , Space
+ , Str "Example"
+ , Space
+ , Str "Book"
+ ]
+ ( "#book01" , "" )
+ , Str "."
+ ]
+ ]
]
, Header
- 1
+ 2
( "ch02" , [] , [] )
[ Str "The" , Space , Str "Second" , Space , Str "Chapter" ]
, Para
[ Str "Some" , Space , Str "content" , Space , Str "here" ]
, Header
1
+ ( "part01" , [] , [] )
+ [ Str "Later" , Space , Str "Part" ]
+ , Header
+ 2
( "ch03" , [] , [] )
[ Str "The" , Space , Str "Third" , Space , Str "Chapter" ]
, Para
[ Str "Some" , Space , Str "content" , Space , Str "here" ]
, Header
- 1
+ 2
( "ch04" , [] , [ ( "titleabbrev" , "Chapter 4" ) ] )
[ Str "The" , Space , Str "Fourth" , Space , Str "Chapter" ]
, Para