Coverage for phml\nodes\comment.py: 100%
14 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -0600
1from .literal import Literal
4class Comment(Literal):
5 """Comment (Literal) represents a Comment ([DOM]).
7 Example:
8 ```html
9 <!--Charlie-->
10 ```
11 """
13 def stringify(self, indent: int = 0) -> str:
14 """Build indented html string of html comment.
16 Returns:
17 str: Built html of comment
18 """
19 lines = [line for line in self.value.split("\n") if line.strip() != ""]
20 if len(lines) > 1:
21 start = f"{' ' * indent}<!--{lines[0].rstrip()}"
22 end = f"{' ' * indent}{lines[-1].lstrip()}-->"
23 for i in range(1, len(lines) - 1):
24 lines[i] = (' ' * indent) + lines[i].strip()
25 lines = [start, *lines[1:-1], end]
26 return "\n".join(lines)
27 return ' ' * indent + f"<!--{self.value}-->"
29 def __repr__(self) -> str:
30 return f"literal.comment(value: {self.value})"