git.iko.soy/typeable/pandoc
on master help sign in
Improve text generated for <xref> by employing docbook-xsl heuristics
eee9925Frerich Raabe
src/Text/Pandoc/Readers/DocBook.hs+16−2
@@ -1024,8 +1024,22 @@ parseInline (Elem e) =
1024 findElementById idString content
1024 findElementById idString content
1025 = asum [filterElement (\x -> attrValue "id" x == idString) el | Elem el <- content]
1025 = asum [filterElement (\x -> attrValue "id" x == idString) el | Elem el <- content]
1026
1026
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.
1027 xrefTitleByElem el
1030 xrefTitleByElem el
1028− | null xrefLabel = "???"
1031+ | not (null xrefLabel) = xrefLabel
1029− | otherwise = 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"
1030 where
1042 where
1031 xrefLabel = attrValue "xreflabel" el
1043 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 []})
2[Header 1 ("ch01",[],[]) [Str "XRef",Space,Str "Samples"]
2[Header 1 ("ch01",[],[]) [Str "XRef",Space,Str "Samples"]
3,Para [Str "This",Space,Str "paragraph",Space,Str "demonstrates",Space,Str "several",Space,Str "features",Space,Str "of",Space,Str "XRef."]
3,Para [Str "This",Space,Str "paragraph",Space,Str "demonstrates",Space,Str "several",Space,Str "features",Space,Str "of",Space,Str "XRef."]
4,BulletList
4,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 "."]]
6 ,[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 "."]]
6 ,[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 "."]]
7 ,[Para [Str "A",Space,Str "link",Space,Str "with",Space,Str "an",Space,Str "EndTerm:",Space,Link [Str "Chapter 4"] ("#ch04",""),Str "."]]
7 ,[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 "."]]
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 "???"] ("#func01",""),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 "."]]]
10,Header 1 ("ch02",[],[]) [Str "The",Space,Str "Second",Space,Str "Chapter"]
10,Header 1 ("ch02",[],[]) [Str "The",Space,Str "Second",Space,Str "Chapter"]
11,Para [Str "Some",Space,Str "content",Space,Str "here"]
11,Para [Str "Some",Space,Str "content",Space,Str "here"]
12,Header 1 ("ch03",[],[]) [Str "The",Space,Str "Third",Space,Str "Chapter"]
12,Header 1 ("ch03",[],[]) [Str "The",Space,Str "Third",Space,Str "Chapter"]