diff --git a/example.html b/example.html index c8440dc..e0e0c5c 100644 --- a/example.html +++ b/example.html @@ -1 +1,393 @@ -The Title

The Title

The Subject
The Author
The Place, 2020-01-01

The First Section

The first paragraph.

The second paragraph.

We allow attachments. Nice, isn't it?

The Second Section

The Subsection

The first paragraph.

The second paragraph.

The second paragraph.

A definition list

This is a definition list:

term 1

definition 1

term 2

definition 2

A table

This is a table, but may be not that much pretty:

Heading 1Heading 2
A1A2
B1B2

A list

This is an unordered list, a long one:

\ No newline at end of file + + + + The Title + + + + + + + + +
+

+ The Title +

+

+ The Subject +
+ The Author +
+ The Place, 2020-01-01 +

+
+

+ The First Section +

+

+ The first paragraph. +

+

+ The second paragraph. +

+

+ We allow + + attachments + + . Nice, isn't it? +

+
+
+

+ The Second Section +

+

+ The Subsection +

+

+ The first paragraph. +

+

+ The second paragraph. +

+

+ The second paragraph. +

+
+
+

+ A definition list +

+

+ This is a definition list: +

+
+
+ term 1 +
+
+

+ definition 1 +

+
+
+ term 2 +
+
+

+ definition 2 +

+
+
+
+
+

+ A table +

+

+ This is a table, but may be not that much pretty: +

+ + + + + + + + + + + + + + + + + +
+ Heading 1 + + Heading 2 +
+ A1 + + A2 +
+ B1 + + B2 +
+
+
+

+ A list +

+

+ This is an unordered list, a long one: +

+ +
+
+ + \ No newline at end of file diff --git a/example.py b/example.py index aec2a62..97a8b87 100644 --- a/example.py +++ b/example.py @@ -102,7 +102,7 @@ from red_tape_kit.html import HTMLRenderer from red_tape_kit.pdf import FPDFRenderer with open('example.html', 'wb') as fp: - HTMLRenderer(doc).render(fp) + HTMLRenderer(doc).render(fp, indent='\t') with open('example.pdf', 'wb') as fp: FPDFRenderer(doc).render(fp) with open('example.docx', 'wb') as fp: diff --git a/red_tape_kit/html.py b/red_tape_kit/html.py index a0114e2..a4c5d17 100644 --- a/red_tape_kit/html.py +++ b/red_tape_kit/html.py @@ -136,5 +136,8 @@ def add_attachment(self, html_el, attachment): a.set('href', f'data:application/octet-stream;base64,{b64_str}') self.add_inline_element(a, attachment.text) - def render(self, f): - ET.ElementTree(self.root).write(f, encoding='utf-8', method='html') + def render(self, f, indent=None): + tree = ET.ElementTree(self.root) + if indent is not None: + ET.indent(tree, space=indent, level=0) + tree.write(f, encoding='utf-8', method='html')