|
13 | 13 | from sphinx.locale import _, __ |
14 | 14 | from sphinx.util import ws_re |
15 | 15 | from sphinx.util.docutils import ReferenceRole, SphinxRole, _normalize_options |
| 16 | +from sphinx.util.nodes import make_index |
16 | 17 |
|
17 | 18 | if TYPE_CHECKING: |
18 | 19 | from collections.abc import Sequence |
@@ -198,20 +199,17 @@ class CVE(ReferenceRole): |
198 | 199 | _BASE_URL: Final = 'https://www.cve.org/CVERecord?id=CVE-' |
199 | 200 |
|
200 | 201 | def run(self) -> tuple[list[Node], list[system_message]]: |
201 | | - target_id = f'index-{self.env.new_serialno("index")}' |
202 | | - entries = [ |
203 | | - ( |
204 | | - 'single', |
205 | | - _('Common Vulnerabilities and Exposures; CVE %s') % self.target, |
206 | | - target_id, |
207 | | - '', |
208 | | - None, |
209 | | - ) |
210 | | - ] |
211 | | - |
212 | | - index = addnodes.index(entries=entries) |
213 | | - target = nodes.target('', '', ids=[target_id]) |
214 | | - self.inliner.document.note_explicit_target(target) |
| 202 | + index_nodes, _targetid = make_index( |
| 203 | + self.inliner.document, |
| 204 | + [ |
| 205 | + ( |
| 206 | + 'single', |
| 207 | + _('Common Vulnerabilities and Exposures; CVE %s') % self.target, |
| 208 | + ) |
| 209 | + ], |
| 210 | + inline=True, |
| 211 | + ) |
| 212 | + index, target = index_nodes |
215 | 213 |
|
216 | 214 | try: |
217 | 215 | refuri = self.build_uri() |
@@ -243,20 +241,12 @@ class CWE(ReferenceRole): |
243 | 241 | _BASE_URL: Final = 'https://cwe.mitre.org/data/definitions/' |
244 | 242 |
|
245 | 243 | def run(self) -> tuple[list[Node], list[system_message]]: |
246 | | - target_id = f'index-{self.env.new_serialno("index")}' |
247 | | - entries = [ |
248 | | - ( |
249 | | - 'single', |
250 | | - _('Common Weakness Enumeration; CWE %s') % self.target, |
251 | | - target_id, |
252 | | - '', |
253 | | - None, |
254 | | - ) |
255 | | - ] |
256 | | - |
257 | | - index = addnodes.index(entries=entries) |
258 | | - target = nodes.target('', '', ids=[target_id]) |
259 | | - self.inliner.document.note_explicit_target(target) |
| 244 | + index_nodes, _targetid = make_index( |
| 245 | + self.inliner.document, |
| 246 | + [('single', _('Common Weakness Enumeration; CWE %s') % self.target)], |
| 247 | + inline=True, |
| 248 | + ) |
| 249 | + index, target = index_nodes |
260 | 250 |
|
261 | 251 | try: |
262 | 252 | refuri = self.build_uri() |
@@ -286,20 +276,12 @@ def build_uri(self) -> str: |
286 | 276 |
|
287 | 277 | class PEP(ReferenceRole): |
288 | 278 | def run(self) -> tuple[list[Node], list[system_message]]: |
289 | | - target_id = 'index-%s' % self.env.new_serialno('index') |
290 | | - entries = [ |
291 | | - ( |
292 | | - 'single', |
293 | | - _('Python Enhancement Proposals; PEP %s') % self.target, |
294 | | - target_id, |
295 | | - '', |
296 | | - None, |
297 | | - ) |
298 | | - ] |
299 | | - |
300 | | - index = addnodes.index(entries=entries) |
301 | | - target = nodes.target('', '', ids=[target_id]) |
302 | | - self.inliner.document.note_explicit_target(target) |
| 279 | + index_nodes, _targetid = make_index( |
| 280 | + self.inliner.document, |
| 281 | + [('single', _('Python Enhancement Proposals; PEP %s') % self.target)], |
| 282 | + inline=True, |
| 283 | + ) |
| 284 | + index, target = index_nodes |
303 | 285 |
|
304 | 286 | try: |
305 | 287 | refuri = self.build_uri() |
@@ -331,13 +313,13 @@ def build_uri(self) -> str: |
331 | 313 |
|
332 | 314 | class RFC(ReferenceRole): |
333 | 315 | def run(self) -> tuple[list[Node], list[system_message]]: |
334 | | - target_id = 'index-%s' % self.env.new_serialno('index') |
335 | 316 | formatted_target = _format_rfc_target(self.target) |
336 | | - entries = [('single', f'RFC; {formatted_target}', target_id, '', None)] |
337 | | - |
338 | | - index = addnodes.index(entries=entries) |
339 | | - target = nodes.target('', '', ids=[target_id]) |
340 | | - self.inliner.document.note_explicit_target(target) |
| 317 | + index_nodes, _targetid = make_index( |
| 318 | + self.inliner.document, |
| 319 | + [('single', f'RFC; {formatted_target}')], |
| 320 | + inline=True, |
| 321 | + ) |
| 322 | + index, target = index_nodes |
341 | 323 |
|
342 | 324 | try: |
343 | 325 | refuri = self.build_uri() |
|
0 commit comments