@@ -61,6 +61,9 @@ class XRefRole(ReferenceRole):
61
61
* `lowercase` to lowercase the target
62
62
* `nodeclass` and `innernodeclass` select the node classes for
63
63
the reference and the content node
64
+ * `title_fmt`: an optional format string using one ``{title}`` variable
65
+ that can be used to customize the rendered text, e.g.
66
+ ``title_fmt=":{title}:"`
64
67
65
68
* Subclassing and overwriting `process_link()` and/or `result_nodes()`.
66
69
"""
@@ -75,6 +78,7 @@ def __init__(
75
78
nodeclass : type [Element ] | None = None ,
76
79
innernodeclass : type [TextElement ] | None = None ,
77
80
warn_dangling : bool = False ,
81
+ title_fmt : str | None = None
78
82
) -> None :
79
83
self .fix_parens = fix_parens
80
84
self .lowercase = lowercase
@@ -83,6 +87,7 @@ def __init__(
83
87
self .nodeclass = nodeclass
84
88
if innernodeclass is not None :
85
89
self .innernodeclass = innernodeclass
90
+ self .title_fmt = title_fmt
86
91
87
92
super ().__init__ ()
88
93
@@ -145,6 +150,8 @@ def create_xref_node(self) -> tuple[list[Node], list[system_message]]:
145
150
self .env , refnode , self .has_explicit_title , title , target
146
151
)
147
152
refnode ['reftarget' ] = target
153
+ if self .title_fmt is not None :
154
+ title = self .title_fmt .format (title = title )
148
155
refnode += self .innernodeclass (self .rawtext , title , classes = self .classes )
149
156
150
157
return self .result_nodes (self .inliner .document , self .env , refnode , is_ref = True )
0 commit comments