aboutsummaryrefslogtreecommitdiff
path: root/muppet/data/html.py
diff options
context:
space:
mode:
Diffstat (limited to 'muppet/data/html.py')
-rw-r--r--muppet/data/html.py95
1 files changed, 0 insertions, 95 deletions
diff --git a/muppet/data/html.py b/muppet/data/html.py
deleted file mode 100644
index df4f0f2..0000000
--- a/muppet/data/html.py
+++ /dev/null
@@ -1,95 +0,0 @@
-"""HTML Renderer."""
-
-from . import (
- Tag,
- Declaration,
- Link,
- ID,
- Documentation,
- Renderer,
- Indentation,
- render,
-)
-from collections.abc import Sequence
-import html
-from dataclasses import dataclass, field
-
-
-@dataclass
-class HTMLRenderer(Renderer):
- """
- Render the document into HTML.
-
- :param param_documentation:
- A dictionary containing (rendered) documentation for each
- parameter of the class or resource type currently being
- rendered.
- """
-
- param_documentation: dict[str, str] = field(default_factory=dict)
-
- def render_tag(self, tag: Tag) -> str:
- """Attaches all tags as classes in a span."""
- inner: str
- # if isinstance(tag.item, str):
- # inner = tag.item
- if isinstance(tag.item, Sequence):
- inner = ''.join(render(self, i) for i in tag.item)
- else:
- inner = render(self, tag.item)
-
- out = ''
- if isinstance(tag, Declaration):
- if comment := self.param_documentation.get(tag.variable):
- if isinstance(tag.item, list) \
- and tag.item \
- and isinstance(tag.item[0], Indentation):
- out += render(self, tag.item[0])
- out += f'<span class="comment">{comment.strip()}</span>\n'
-
- tags = ' '.join(tag.tags)
- out += f'<span class="{tags}">{inner}</span>'
- return out
-
- def render_link(self, link: Link) -> str:
- """Wrap the value in an anchor tag."""
- return f'<a href="{link.target}">{render(self, link.item)}</a>'
-
- def render_id(self, id: ID) -> str:
- """Render an object with a wrapping id tag into a string."""
- return f'<span id="{id.id}">{render(self, id.item)}</span>'
-
- def render_doc(self, doc: Documentation) -> str:
- """
- Set up a documentation anchor span, with content.
-
- The anchor will contain both the item, rendered as normally,
- and a div with class documentation.
-
- The suggested CSS for this is::
-
- .documentation-anchor {
- display: relative;
- }
-
- .documentation-anchor .documentation {
- display: none;
- }
-
- .documentation-anchor:hover .documentation {
- display: block;
- }
- """
- s = '<span class="documentation-anchor">'
- s += render(self, doc.item)
- s += f'<div class="documentation">{doc.documentation}</div>'
- s += '</span>'
- return s
-
- def render_indent(self, ind: Indentation) -> str:
- """Return indentation width * 2 as a string."""
- return ' ' * ind.depth * 2
-
- def render_str(self, s: str) -> str:
- """HTML escape and return the given string."""
- return html.escape(s)