|
| 1 | +""" |
| 2 | +# PyHTML Enhanced / Tags / Dangerous raw HTML |
| 3 | +
|
| 4 | +Definition for the DangerousRawHtml tag. |
| 5 | +""" |
| 6 | +from ..__tag_base import Tag |
| 7 | + |
| 8 | + |
| 9 | +class DangerousRawHtml(Tag): |
| 10 | + """ |
| 11 | + Raw HTML as a string. This is embedded directly within the rendered output. |
| 12 | +
|
| 13 | + ## Warning |
| 14 | +
|
| 15 | + This will blindly accept any text as HTML, which is EXTREMELY DANGEROUS! |
| 16 | + (Mis)using this could result in issues ranging from broken output to major |
| 17 | + security vulnerabilities such as |
| 18 | + [cross-site scripting](https://en.wikipedia.org/wiki/Cross-site_scripting). |
| 19 | +
|
| 20 | + Do not use this unless absolutely necessary. |
| 21 | + """ |
| 22 | + def __init__(self, text: str) -> None: |
| 23 | + """ |
| 24 | + Raw HTML as a string. This is embedded directly within the rendered |
| 25 | + output. |
| 26 | +
|
| 27 | + ## Warning |
| 28 | +
|
| 29 | + This will blindly accept any text as HTML, which is EXTREMELY |
| 30 | + DANGEROUS! (Mis)using this could result in issues ranging from broken |
| 31 | + output to major security vulnerabilities such as |
| 32 | + [cross-site scripting](https://en.wikipedia.org/wiki/Cross-site_scripting). |
| 33 | +
|
| 34 | + Do not use this unless absolutely necessary. |
| 35 | + """ |
| 36 | + self.html_data = text |
| 37 | + super().__init__() |
| 38 | + |
| 39 | + def __call__(self): |
| 40 | + raise TypeError('DangerousRawHtml tags are not callable') |
| 41 | + |
| 42 | + def _get_tag_name(self) -> str: |
| 43 | + # Ignore coverage since this is only implemented to satisfy inheritance |
| 44 | + # and is never used since we override _render |
| 45 | + return '!!!DANGEROUS RAW HTML!!!' # pragma: no cover |
| 46 | + |
| 47 | + def _render(self) -> list[str]: |
| 48 | + return self.html_data.splitlines() |
0 commit comments