File: colour_preview.py

package info (click to toggle)
python-discord 2.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: python: 46,013; javascript: 363; makefile: 154
file content (51 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (3)
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
50
51
from __future__ import annotations
from typing import Dict, Any

from sphinx.util.docutils import SphinxDirective
from docutils.parsers.rst import directives
from docutils import nodes

import sphinx
from sphinx.application import Sphinx


class colour_input(nodes.General, nodes.Element):
    pass


def visit_colour_node(self, node):
    self.body.append(
        self.starttag(
            node,
            'input',
            empty=True,
            type='color',
            value=node.rawsource,
            disabled='',
            CLASS=node.attributes.get('class', ''),
        )
    )


def depart_colour_node(self, node):
    pass


class ColourDirective(SphinxDirective):
    required_arguments = 1
    has_content = False

    option_spec = {
        'class': directives.class_option,
    }

    def run(self):
        node = colour_input(self.arguments[0], **self.options)
        self.state.nested_parse(self.content, self.content_offset, node)
        return [node]


def setup(app: Sphinx) -> Dict[str, Any]:
    app.add_node(colour_input, html=(visit_colour_node, depart_colour_node))
    app.add_directive('colour', ColourDirective)
    return {'version': sphinx.__display_version__, 'parallel_read_safe': True}