| Total Complexity | 2 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 83.33% |
| Changes | 0 | ||
| 1 | 1 | from typing import Any |
|
| 2 | |||
| 3 | 1 | from sdoc.helper.Html import Html |
|
| 4 | 1 | from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
|
| 5 | 1 | from sdoc.sdoc2.node.HyperlinkNode import HyperlinkNode |
|
| 6 | 1 | from sdoc.sdoc2.NodeStore import NodeStore |
|
| 7 | |||
| 8 | |||
| 9 | 1 | class HyperlinkHtmlFormatter(HtmlFormatter): |
|
| 10 | """ |
||
| 11 | HtmlFormatter for generating HTML code for hyperlinks. |
||
| 12 | """ |
||
| 13 | |||
| 14 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 15 | 1 | def generate(self, node: HyperlinkNode, file: Any) -> None: |
|
| 16 | """ |
||
| 17 | Generates the HTML code for a hyperlink node. |
||
| 18 | |||
| 19 | :param HyperlinkNode node: The hyperlink node. |
||
| 20 | :param any file: The output file. |
||
| 21 | """ |
||
| 22 | file.write(HyperlinkHtmlFormatter.get_html(node)) |
||
| 23 | |||
| 24 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 25 | 1 | @staticmethod |
|
| 26 | 1 | def get_html(node: HyperlinkNode) -> str: |
|
| 27 | """ |
||
| 28 | Returns string with generated HTML tag. |
||
| 29 | |||
| 30 | :param HyperlinkNode node: The hyperlink node. |
||
| 31 | """ |
||
| 32 | return Html.generate_element('a', node.get_html_attributes(), node.argument) |
||
| 33 | |||
| 34 | |||
| 35 | # ---------------------------------------------------------------------------------------------------------------------- |
||
| 36 | NodeStore.register_formatter('hyperlink', 'html', HyperlinkHtmlFormatter) |
||
| 37 |