Docbook writer: Interpret links without contents as cross-references (#7360)

Links without text contents are converted to `<xref>` elements. DocBook
processors will generate appropriate cross-reference text when presented
with an xref element.
This commit is contained in:
Jan Tojnar 2022-02-06 23:05:20 +01:00 committed by GitHub
parent faf99ad356
commit 876859f9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -429,7 +429,9 @@ inlineToDocbook opts (Link attr txt (src, _))
| otherwise = do
version <- ask
(if "#" `T.isPrefixOf` src
then inTags False "link" $ ("linkend", writerIdentifierPrefix opts <> T.drop 1 src) : idAndRole attr
then let tag = if null txt then "xref" else "link"
in inTags False tag $
("linkend", writerIdentifierPrefix opts <> T.drop 1 src) : idAndRole attr
else if version == DocBook5
then inTags False "link" $ ("xlink:href", src) : idAndRole attr
else inTags False "ulink" $ ("url", src) : idAndRole attr )

View file

@ -32,9 +32,11 @@ which is in turn shorthand for
-}
infix 4 =:
(=:) :: (ToString a, ToPandoc a)
=> String -> (a, String) -> TestTree
(=:), testDb4, testDb5 :: (ToString a, ToPandoc a)
=> String -> (a, String) -> TestTree
(=:) = test docbook
testDb4 = test docbook
testDb5 = test docbook5
lineblock :: Blocks
lineblock = para ("some text" <> linebreak <>
@ -47,7 +49,19 @@ lineblock_out = [ "<literallayout>some text"
]
tests :: [TestTree]
tests = [ testGroup "line blocks"
tests = [ testGroup "inline elements"
[ testGroup "links"
[ testDb4 "db4 external link" $ link "https://example.com" "" "Hello"
=?> "<ulink url=\"https://example.com\">Hello</ulink>"
, testDb5 "db5 external link" $ link "https://example.com" "" "Hello"
=?> "<link xlink:href=\"https://example.com\">Hello</link>"
, testDb5 "anchor" $ link "#foo" "" "Hello"
=?> "<link linkend=\"foo\">Hello</link>"
, testDb5 "automatic anchor" $ link "#foo" "" ""
=?> "<xref linkend=\"foo\"></xref>"
]
]
, testGroup "line blocks"
[ "none" =: para "This is a test"
=?> unlines
[ "<para>"