summaryrefslogtreecommitdiff
path: root/docs/_exts/formatting.py
blob: ad40a7bd3a7597740662c1ebb9b5be4d6f3b5d1d (plain)
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
42
43
44
45
46
47
48
49
# formatting.py
# Sphinx extension providing formatting for Gallium-specific data
# (c) Corbin Simpson 2010
# Public domain to the extent permitted; contact author for special licensing

import docutils.nodes
import sphinx.addnodes

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

def parse_opcode(env, sig, signode):
    opcode, desc = sig.split("-", 1)
    opcode = opcode.strip().upper()
    desc = " (%s)" % desc.strip()
    signode += sphinx.addnodes.desc_name(opcode, opcode)
    signode += sphinx.addnodes.desc_annotation(desc, desc)
    return opcode


def ext_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    text = utils.unescape(text)
    has_explicit_title, title, ext = split_explicit_title(text)

    parts = ext.split('_', 2)
    if parts[0] == 'VK':
        full_url = f'https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/{ext}.html'
    elif parts[0] == 'GL':
        full_url = f'https://registry.khronos.org/OpenGL/extensions/{parts[1]}/{parts[1]}_{parts[2]}.txt'
    else:
        raise Exception(f'Unexpected API: {parts[0]}')

    pnode = nodes.reference(title, title, internal=False, refuri=full_url)
    return [pnode], []

def vkfeat_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    text = utils.unescape(text)
    has_explicit_title, title, ext = split_explicit_title(text)

    full_url = f'https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#features-{ext}'

    pnode = nodes.reference(title, title, internal=False, refuri=full_url)
    return [pnode], []

def setup(app):
    app.add_object_type("opcode", "opcode", "%s (TGSI opcode)",
        parse_opcode)
    app.add_role('ext', ext_role)
    app.add_role('vk-feat', vkfeat_role)