File: domainrefs.py

package info (click to toggle)
python-mitogen 0.3.25~a2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,220 kB
  • sloc: python: 21,989; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (41 lines) | stat: -rw-r--r-- 1,001 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

import functools
import re

import docutils.nodes
import docutils.utils


CUSTOM_RE = re.compile('(.*) <(.*)>')


def role(config, role, rawtext, text, lineno, inliner, options={}, content=[]):
    template = 'https://docs.ansible.com/ansible/latest/modules/%s_module.html'

    match = CUSTOM_RE.match(text)
    if match:  # "custom text <real link>"
        title = match.group(1)
        text = match.group(2)
    elif text.startswith('~'):  # brief
        text = text[1:]
        title = config.get('brief', '%s') % (
            docutils.utils.unescape(text),
        )
    else:
        title = config.get('text', '%s') % (
            docutils.utils.unescape(text),
        )

    node = docutils.nodes.reference(
        rawsource=rawtext,
        text=title,
        refuri=config['url'] % (text,),
        **options
    )

    return [node], []


def setup(app):
    for name, info in app.config._raw_config['domainrefs'].items():
        app.add_role(name, functools.partial(role, info))