File: ext_releaseref.py

package info (click to toggle)
streamlink 7.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,428 kB
  • sloc: python: 49,104; sh: 184; makefile: 145
file content (25 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Creates links that allows substituting the current release
within the title or target."""

import os.path

from docutils import nodes
from sphinx.util.nodes import split_explicit_title


def releaseref_role(name, rawtext, text, lineno, inliner, options=None, content=None):
    config = inliner.document.settings.env.config
    text = text.replace("|version|", config.version)
    text = text.replace("|release|", config.release)

    has_explicit_title, title, target = split_explicit_title(text)
    if not has_explicit_title:
        title = os.path.basename(target)

    node = nodes.reference(rawtext, title, refuri=target, **(options or {}))

    return [node], []


def setup(app):
    app.add_role("releaseref", releaseref_role)