1
|
|
|
""" |
2
|
|
|
SDoc |
3
|
|
|
|
4
|
|
|
Copyright 2016 Set Based IT Consultancy |
5
|
|
|
|
6
|
|
|
Licence MIT |
7
|
|
|
""" |
8
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
9
|
|
|
from sdoc.helper.Html import Html |
10
|
|
|
from sdoc.sdoc2 import node_store |
11
|
|
|
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class UnknownHtmlFormatter(HtmlFormatter): |
15
|
|
|
""" |
16
|
|
|
HtmlFormatter for generating HTML code for paragraph. |
17
|
|
|
""" |
18
|
|
|
|
19
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
20
|
|
|
def generate(self, node, file): |
21
|
|
|
""" |
22
|
|
|
Generates the HTML code for a paragraph node. |
23
|
|
|
|
24
|
|
|
:param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node. |
25
|
|
|
:param file file: The output file. |
26
|
|
|
""" |
27
|
|
|
self.write_into_file(node, file) |
28
|
|
|
|
29
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
30
|
|
|
def generate_chapter(self, node, file): |
31
|
|
|
""" |
32
|
|
|
Generates the HTML code for a paragraph node. |
33
|
|
|
|
34
|
|
|
:param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node. |
35
|
|
|
:param file file: The output file. |
36
|
|
|
""" |
37
|
|
|
if file: |
38
|
|
|
self.write_into_file(node, file) |
39
|
|
|
|
40
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
41
|
|
|
def write_into_file(self, node, file): |
|
|
|
|
42
|
|
|
""" |
43
|
|
|
Writes into opened file. |
44
|
|
|
|
45
|
|
|
:param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node. |
46
|
|
|
:param file file: The output file. |
47
|
|
|
""" |
48
|
|
|
html = 'Unknown SDoc2 command <span style="font-weight:bold">{0!s}</span> at {1!s}'.format( |
49
|
|
|
Html.escape(node.name), Html.escape(str(node.position))) |
50
|
|
|
file.write(Html.generate_element('span', {'style': 'color:red'}, html, True)) |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
54
|
|
|
node_store.register_formatter('unknown', 'html', UnknownHtmlFormatter) |
55
|
|
|
|
If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example
could be written as