-
Notifications
You must be signed in to change notification settings - Fork 5
Add JS class #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JS class #81
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1238,27 +1238,19 @@ def _static_extract_serialized_html_deps( | |||||||
# ============================================================================= | ||||||||
# HTML strings | ||||||||
# ============================================================================= | ||||||||
class HTML(str): | ||||||||
""" | ||||||||
Mark a string as raw HTML. This will prevent the string from being escaped when | ||||||||
rendered inside an HTML tag. | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> from htmltools import HTML, div | ||||||||
>>> div("<p>Hello</p>") | ||||||||
<div><p>Hello</p></div> | ||||||||
>>> div(HTML("<p>Hello</p>")) | ||||||||
<div><p>Hello</p></div> | ||||||||
|
||||||||
class RAW(str): | ||||||||
""" | ||||||||
Base class for raw content. | ||||||||
""" | ||||||||
|
||||||||
def __str__(self) -> str: | ||||||||
return self.as_string() | ||||||||
|
||||||||
# HTML() + HTML() should return HTML() | ||||||||
def __add__(self, other: "str| HTML") -> str: | ||||||||
def __add__(self, other: "str| RAW") -> str: | ||||||||
res = str.__add__(self, other) | ||||||||
return HTML(res) if isinstance(other, HTML) else res | ||||||||
return self.__class__(res) if isinstance(other, self.__class__) else res | ||||||||
|
||||||||
def __repr__(self) -> str: | ||||||||
return self.as_string() | ||||||||
|
@@ -1270,6 +1262,31 @@ def as_string(self) -> str: | |||||||
return self + "" | ||||||||
|
||||||||
|
||||||||
class HTML(RAW): | ||||||||
""" | ||||||||
Mark a string as raw HTML. This will prevent the string from being escaped when | ||||||||
rendered inside an HTML tag. | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> from htmltools import HTML, div | ||||||||
>>> div("<p>Hello</p>") | ||||||||
<div><p>Hello</p></div> | ||||||||
>>> div(HTML("<p>Hello</p>")) | ||||||||
<div><p>Hello</p></div> | ||||||||
""" | ||||||||
|
||||||||
pass | ||||||||
|
||||||||
|
||||||||
class JS(RAW): | ||||||||
""" | ||||||||
Mark a string as raw JavaScript. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, is this not true? Now that I think about it, maybe it shouldn't be true? Or at least, |
||||||||
""" | ||||||||
|
||||||||
pass | ||||||||
|
||||||||
|
||||||||
# ============================================================================= | ||||||||
# HTML dependencies | ||||||||
# ============================================================================= | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.