git.iko.soy/typeable/pandoc
on master help sign in
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.

commiteee992520cfe3d0d37185f998339690aae39f2c8 authorFrerich Raabe <raabe@froglogic.com> dateWed 23 Sep 2015, 23:08 (11 years ago) parent35f12b5
2 files changed+19−5
src/Text/Pandoc/Readers/DocBook.hs+16−2 tests/docbook-xref.native+3−3
src/Text/Pandoc/Readers/DocBook.hs+16−2
@@ -1024,8 +1024,22 @@ parseInline (Elem e) =
10241024 findElementById idString content
10251025 = asum [filterElement (\x -> attrValue "id" x == idString) el | Elem el <- content]
10261026
1027+ -- Use the 'xreflabel' attribute for getting the title of a xref link;
1028+ -- if there's no such attribute, employ some heuristics based on what
1029+ -- docbook-xsl does.
10271030 xrefTitleByElem el
1028− | null xrefLabel = "???"
1029− | otherwise = xrefLabel
1031+ | not (null xrefLabel) = xrefLabel
1032+ | otherwise = case qName (elName el) of
1033+ "chapter" -> descendantContent "title" el
1034+ "sect1" -> descendantContent "title" el
1035+ "sect2" -> descendantContent "title" el
1036+ "sect3" -> descendantContent "title" el
1037+ "sect4" -> descendantContent "title" el
1038+ "sect5" -> descendantContent "title" el
1039+ "cmdsynopsis" -> descendantContent "command" el
1040+ "funcsynopsis" -> descendantContent "function" el
1041+ _ -> qName (elName el) ++ "_title"
10301042 where
10311043 xrefLabel = attrValue "xreflabel" el
1044+ descendantContent name = maybe "???" strContent
1045+ . findElement (QName name Nothing Nothing)
tests/docbook-xref.native+3−3
@@ -2,11 +2,11 @@ Pandoc (Meta {unMeta = fromList []})
22[Header 1 ("ch01",[],[]) [Str "XRef",Space,Str "Samples"]
33,Para [Str "This",Space,Str "paragraph",Space,Str "demonstrates",Space,Str "several",Space,Str "features",Space,Str "of",Space,Str "XRef."]
44,BulletList
5− [[Para [Str "A",Space,Str "straight",Space,Str "link",Space,Str "generates",Space,Str "the",Space,Str "cross-reference",Space,Str "text:",Space,Link [Str "???"] ("#ch02",""),Str "."]]
5+ [[Para [Str "A",Space,Str "straight",Space,Str "link",Space,Str "generates",Space,Str "the",Space,Str "cross-reference",Space,Str "text:",Space,Link [Str "The Second Chapter"] ("#ch02",""),Str "."]]
66 ,[Para [Str "A",Space,Str "link",Space,Str "to",Space,Str "an",Space,Str "element",Space,Str "with",Space,Str "an",Space,Str "XRefLabel:",Space,Link [Str "Chapter the Third"] ("#ch03",""),Str "."]]
77 ,[Para [Str "A",Space,Str "link",Space,Str "with",Space,Str "an",Space,Str "EndTerm:",Space,Link [Str "Chapter 4"] ("#ch04",""),Str "."]]
8− ,[Para [Str "A",Space,Str "link",Space,Str "to",Space,Str "an",Space,Str "cmdsynopsis",Space,Str "element:",Space,Link [Str "???"] ("#cmd01",""),Str "."]]
9− ,[Para [Str "A",Space,Str "link",Space,Str "to",Space,Str "an",Space,Str "funcsynopsis",Space,Str "element:",Space,Link [Str "???"] ("#func01",""),Str "."]]]
8+ ,[Para [Str "A",Space,Str "link",Space,Str "to",Space,Str "an",Space,Str "cmdsynopsis",Space,Str "element:",Space,Link [Str "chgrp"] ("#cmd01",""),Str "."]]
9+ ,[Para [Str "A",Space,Str "link",Space,Str "to",Space,Str "an",Space,Str "funcsynopsis",Space,Str "element:",Space,Link [Str "max"] ("#func01",""),Str "."]]]
1010,Header 1 ("ch02",[],[]) [Str "The",Space,Str "Second",Space,Str "Chapter"]
1111,Para [Str "Some",Space,Str "content",Space,Str "here"]
1212,Header 1 ("ch03",[],[]) [Str "The",Space,Str "Third",Space,Str "Chapter"]