summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/DocBook.hs
diff options
context:
space:
mode:
authorFrerich Raabe <raabe@froglogic.com>2015-09-23 23:08:53 +0200
committerFrerich Raabe <raabe@froglogic.com>2015-09-24 18:28:51 +0200
commiteee992520cfe3d0d37185f998339690aae39f2c8 (patch)
tree94a488b638164a9ac581b503d759ba15537431f2 /src/Text/Pandoc/Readers/DocBook.hs
parent35f12b5095799e41b563f47a7923a1d01015c71c (diff)
Improve text generated for <xref> by employing docbook-xsl heuristics
docbook-xsl, a set of XSLT scripts to generate HMTL out of DocBook, tries harder to generate a nice xref text. Depending on the element being linked to, it looks at the title or other descriptive child elements. Let's do that, too.
Diffstat (limited to 'src/Text/Pandoc/Readers/DocBook.hs')
-rw-r--r--src/Text/Pandoc/Readers/DocBook.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
index 164b44b62..9243221f0 100644
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -1024,8 +1024,22 @@ parseInline (Elem e) =
findElementById idString content
= asum [filterElement (\x -> attrValue "id" x == idString) el | Elem el <- content]
+ -- Use the 'xreflabel' attribute for getting the title of a xref link;
+ -- if there's no such attribute, employ some heuristics based on what
+ -- docbook-xsl does.
xrefTitleByElem el
- | null xrefLabel = "???"
- | otherwise = xrefLabel
+ | not (null xrefLabel) = xrefLabel
+ | otherwise = case qName (elName el) of
+ "chapter" -> descendantContent "title" el
+ "sect1" -> descendantContent "title" el
+ "sect2" -> descendantContent "title" el
+ "sect3" -> descendantContent "title" el
+ "sect4" -> descendantContent "title" el
+ "sect5" -> descendantContent "title" el
+ "cmdsynopsis" -> descendantContent "command" el
+ "funcsynopsis" -> descendantContent "function" el
+ _ -> qName (elName el) ++ "_title"
where
xrefLabel = attrValue "xreflabel" el
+ descendantContent name = maybe "???" strContent
+ . findElement (QName name Nothing Nothing)