-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fa158c
commit e976533
Showing
5 changed files
with
66 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
# PyHTML Enhanced / Tags / Comment | ||
Definition for the comment tag. | ||
""" | ||
from ..__tag_base import Tag | ||
from .. import __util as util | ||
|
||
|
||
class Comment(Tag): | ||
""" | ||
An HTML comment. | ||
Renders as: | ||
```html | ||
<!-- [comment text] --> | ||
``` | ||
Note that this does not render as a `<comment>` tag | ||
""" | ||
def __init__(self, text: str) -> None: | ||
""" | ||
An HTML comment. | ||
Renders as: | ||
```html | ||
<!-- [comment text] --> | ||
``` | ||
Note that this does not render as a `<comment>` tag | ||
""" | ||
self.comment_data = text | ||
super().__init__() | ||
|
||
def __call__(self): | ||
raise TypeError('Comment tags are not callable') | ||
|
||
def _get_tag_name(self) -> str: | ||
# Ignore coverage since this is only implemented to satisfy inheritance | ||
# and is never used since we override _render | ||
return '!--' # pragma: no cover | ||
|
||
def _render(self) -> list[str]: | ||
""" | ||
Override of render, to render comments | ||
""" | ||
|
||
return [ | ||
'<!--', | ||
*util.increase_indent( | ||
util.escape_string(self.comment_data).splitlines(), | ||
# FIXME: Yucky magic number | ||
2, | ||
), | ||
'-->' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters