Coverage for phml\nodes\comment.py: 60%

15 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-30 09:38 -0600

1from typing import Iterator 

2 

3from .literal import Literal 

4 

5 

6class Comment(Literal): 

7 """Comment (Literal) represents a Comment ([DOM]). 

8 

9 Example: 

10 ```html 

11 <!--Charlie--> 

12 ``` 

13 """ 

14 

15 def stringify(self, indent: int = 0) -> str: 

16 """Build indented html string of html comment. 

17 

18 Returns: 

19 str: Built html of comment 

20 """ 

21 lines = [line.lstrip() for line in self.value.split("\n") if line.strip() != ""] 

22 if len(lines) > 1: 

23 start = f"{' ' * indent}<!--{lines[0]}" 

24 end = f"{' ' * indent}{lines[-1]}-->" 

25 for i in range(1, len(lines) - 1): 

26 lines[i] = (' ' * indent) + lines[i].strip() 

27 lines = [start, *lines[1:-1], end] 

28 return "\n".join(lines) 

29 return ' ' * indent + f"<!--{self.value}-->" 

30 

31 def __repr__(self) -> str: 

32 return f"literal.comment(value: {self.value})"