File: icons.py

package info (click to toggle)
blender-doc 4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 253,604 kB
  • sloc: python: 13,030; javascript: 322; makefile: 113; sh: 107
file content (40 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download
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
from typing import Tuple, List

from docutils import nodes
from sphinx.application import Sphinx
from sphinx.writers.html5 import HTML5Translator
from sphinx.util.docutils import SphinxRole


class bl_icon(nodes.container):
    pass


def visit_bl_icon(self: HTML5Translator, node: bl_icon):
    """Create a span element with associated CSS classes."""
    self.body.append(f'<span class="{" ".join(node["classes"])}"></span>')
    raise nodes.SkipNode()


class IconsRole(SphinxRole):
    """A interpreted text role to use icons in lines of text."""

    def run(self) -> Tuple[List[nodes.Node], List[nodes.system_message]]:
        path, classes = (self.text, "")
        if ";" in self.text:
            path, classes = self.text.split(";")[:2]
        class_list = [
            "bl-icons-{}".format(self.text),
        ]
        div = bl_icon(path, classes=class_list)
        return [div], []


def setup(app: Sphinx):
    app.add_role("bl-icon", IconsRole())
    app.add_node(bl_icon, html=(visit_bl_icon, None))

    return {
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }