summaryrefslogtreecommitdiff
path: root/logilab/common/ureports/html_writer.py
diff options
context:
space:
mode:
Diffstat (limited to 'logilab/common/ureports/html_writer.py')
-rw-r--r--logilab/common/ureports/html_writer.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/logilab/common/ureports/html_writer.py b/logilab/common/ureports/html_writer.py
index 989662f..0783075 100644
--- a/logilab/common/ureports/html_writer.py
+++ b/logilab/common/ureports/html_writer.py
@@ -20,16 +20,19 @@ __docformat__ = "restructuredtext en"
from logilab.common.ureports import BaseWriter
+from logilab.common.ureports.nodes import (Section, Title, Table, List,
+ Paragraph, Link, VerbatimText, Text)
+from typing import Any
class HTMLWriter(BaseWriter):
"""format layouts as HTML"""
- def __init__(self, snippet=None):
+ def __init__(self, snippet: int = None) -> None:
super(HTMLWriter, self).__init__()
self.snippet = snippet
- def handle_attrs(self, layout):
+ def handle_attrs(self, layout: Any) -> str:
"""get an attribute string from layout member attributes"""
attrs = u''
klass = getattr(layout, 'klass', None)
@@ -40,20 +43,20 @@ class HTMLWriter(BaseWriter):
attrs += u' id="%s"' % nid
return attrs
- def begin_format(self, layout):
+ def begin_format(self, layout: Any) -> None:
"""begin to format a layout"""
super(HTMLWriter, self).begin_format(layout)
if self.snippet is None:
self.writeln(u'<html>')
self.writeln(u'<body>')
- def end_format(self, layout):
+ def end_format(self, layout: Any) -> None:
"""finished to format a layout"""
if self.snippet is None:
self.writeln(u'</body>')
self.writeln(u'</html>')
- def visit_section(self, layout):
+ def visit_section(self, layout: Section) -> None:
"""display a section as html, using div + h[section level]"""
self.section += 1
self.writeln(u'<div%s>' % self.handle_attrs(layout))
@@ -61,13 +64,13 @@ class HTMLWriter(BaseWriter):
self.writeln(u'</div>')
self.section -= 1
- def visit_title(self, layout):
+ def visit_title(self, layout: Title) -> None:
"""display a title using <hX>"""
self.write(u'<h%s%s>' % (self.section, self.handle_attrs(layout)))
self.format_children(layout)
self.writeln(u'</h%s>' % self.section)
- def visit_table(self, layout):
+ def visit_table(self, layout: Table) -> None:
"""display a table as html"""
self.writeln(u'<table%s>' % self.handle_attrs(layout))
table_content = self.get_table_content(layout)
@@ -91,14 +94,14 @@ class HTMLWriter(BaseWriter):
self.writeln(u'</tr>')
self.writeln(u'</table>')
- def visit_list(self, layout):
+ def visit_list(self, layout: List) -> None:
"""display a list as html"""
self.writeln(u'<ul%s>' % self.handle_attrs(layout))
for row in list(self.compute_content(layout)):
self.writeln(u'<li>%s</li>' % row)
self.writeln(u'</ul>')
- def visit_paragraph(self, layout):
+ def visit_paragraph(self, layout: Paragraph) -> None:
"""display links (using <p>)"""
self.write(u'<p>')
self.format_children(layout)
@@ -110,19 +113,19 @@ class HTMLWriter(BaseWriter):
self.format_children(layout)
self.write(u'</span>')
- def visit_link(self, layout):
+ def visit_link(self, layout: Link) -> None:
"""display links (using <a>)"""
self.write(u' <a href="%s"%s>%s</a>' % (layout.url,
self.handle_attrs(layout),
layout.label))
- def visit_verbatimtext(self, layout):
+ def visit_verbatimtext(self, layout: VerbatimText) -> None:
"""display verbatim text (using <pre>)"""
self.write(u'<pre>')
self.write(layout.data.replace(u'&', u'&amp;').replace(u'<', u'&lt;'))
self.write(u'</pre>')
- def visit_text(self, layout):
+ def visit_text(self, layout: Text) -> None:
"""add some text"""
data = layout.data
if layout.escaped: