1
|
1 |
|
from typing import Any |
2
|
|
|
|
3
|
1 |
|
from sdoc.helper.Html import Html |
4
|
1 |
|
from sdoc.sdoc2 import in_scope, out_scope |
5
|
1 |
|
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
6
|
1 |
|
from sdoc.sdoc2.node.DocumentNode import DocumentNode |
7
|
1 |
|
from sdoc.sdoc2.NodeStore import NodeStore |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
View Code Duplication |
class DocumentHtmlFormatter(HtmlFormatter): |
|
|
|
|
11
|
|
|
""" |
12
|
|
|
HtmlFormatter for generating HTML code for document node. |
13
|
|
|
""" |
14
|
|
|
|
15
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
16
|
1 |
|
def generate(self, node: DocumentNode, file: Any) -> None: |
17
|
|
|
""" |
18
|
|
|
Generates the HTML code for a document node. |
19
|
|
|
|
20
|
|
|
:param DocumentNode node: The document node. |
21
|
|
|
:param any file: The output file. |
22
|
|
|
""" |
23
|
1 |
|
self.generate_document_node(node, file) |
24
|
|
|
|
25
|
1 |
|
HtmlFormatter.generate(self, node, file) |
26
|
|
|
|
27
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
28
|
1 |
|
@staticmethod |
29
|
1 |
|
def generate_document_node(node: DocumentNode, file: Any) -> None: |
30
|
|
|
""" |
31
|
|
|
Generates the HTML code for heading node. |
32
|
|
|
|
33
|
|
|
:param DocumentNode node: The document node. |
34
|
|
|
:param any file: The output file. |
35
|
|
|
""" |
36
|
1 |
|
file.write('<div class="sdoc-document-title-outer">') |
37
|
1 |
|
if node.title_node_id: |
38
|
|
|
title_node = in_scope(node.title_node_id) |
39
|
|
|
file.write(Html.generate_element('h1', {}, title_node.argument)) |
40
|
|
|
out_scope(title_node) |
41
|
|
|
|
42
|
1 |
|
file.write('<div class="sdoc-document-title-inner">') |
43
|
|
|
|
44
|
1 |
|
if node.date_node_id: |
45
|
|
|
date_node = in_scope(node.date_node_id) |
46
|
|
|
if date_node.argument: |
47
|
|
|
file.write(Html.generate_element('span', {'class': 'sdoc-document-date'}, date_node.argument)) |
48
|
|
|
out_scope(date_node) |
49
|
|
|
|
50
|
1 |
|
if node.version_node_id: |
51
|
|
|
version_node = in_scope(node.version_node_id) |
52
|
|
|
if version_node.argument: |
53
|
|
|
file.write(Html.generate_element('span', {'class': 'sdoc-document-version'}, version_node.argument)) |
54
|
|
|
out_scope(version_node) |
55
|
|
|
|
56
|
1 |
|
file.write('</div>') |
57
|
1 |
|
file.write('</div>') |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
61
|
|
|
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter) |
62
|
|
|
|