File: css_diagram_role.py

package info (click to toggle)
python-tinycss2 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: python: 2,527; makefile: 21; sh: 6
file content (20 lines) | stat: -rw-r--r-- 526 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
"""
A Sphinx extension adding a 'css' role creating links to
the spec’s railroad diagrams.

"""

from docutils import nodes


def role_fn(_name, rawtext, text, lineno, inliner, options={}, content=()):
    ref = 'https://www.w3.org/TR/css-syntax-3/#%s-diagram' % text.replace(
        ' ', '-')
    if text.endswith(('-token', '-block')):
        text = '<%s>' % text
    ref = nodes.reference(rawtext, text, refuri=ref, **options)
    return [ref], []


def setup(app):
    app.add_role_to_domain('py', 'diagram', role_fn)