debian-python-tinycss2/docs/css_diagram_role.py

22 lines
543 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: utf8
"""
A Sphinx extension adding a 'css' role creating links to
the specs railroad diagrams.
"""
from docutils import nodes
def role_fn(_name, rawtext, text, lineno, inliner, options={}, content=()):
ref = 'http://dev.w3.org/csswg/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)