-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
gh-137836: Support more RAWTEXT and PLAINTEXT elements in HTMLParser #137837
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
Changes from 3 commits
2153a4c
66827e0
c8429be
2219106
a46e28b
9971a24
69a2b33
08f4835
428abe1
a60ed6e
350ce25
03d3348
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 |
|---|---|---|
|
|
@@ -127,17 +127,23 @@ class HTMLParser(_markupbase.ParserBase): | |
| argument. | ||
| """ | ||
|
|
||
| CDATA_CONTENT_ELEMENTS = ("script", "style") | ||
| # See the HTML5 specs section "13.4 Parsing HTML fragments". | ||
| # https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments | ||
| CDATA_CONTENT_ELEMENTS = ("script", "style", "xmp", "iframe", "noembed", "noframes") | ||
serhiy-storchaka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RCDATA_CONTENT_ELEMENTS = ("textarea", "title") | ||
|
|
||
| def __init__(self, *, convert_charrefs=True): | ||
| def __init__(self, *, convert_charrefs=True, scripting=False): | ||
| """Initialize and reset this instance. | ||
|
|
||
| If convert_charrefs is True (the default), all character references | ||
| If convert_charrefs is true (the default), all character references | ||
| are automatically converted to the corresponding Unicode characters. | ||
|
|
||
| If scripting is true, the noscript element is parsed in the | ||
| RAWTEXT mode. | ||
serhiy-storchaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| super().__init__() | ||
| self.convert_charrefs = convert_charrefs | ||
| self.scripting = scripting | ||
| self.reset() | ||
|
|
||
| def reset(self): | ||
|
|
@@ -448,6 +454,11 @@ def parse_starttag(self, i): | |
| self.set_cdata_mode(tag) | ||
| elif tag in self.RCDATA_CONTENT_ELEMENTS: | ||
| self.set_cdata_mode(tag, escapable=True) | ||
| elif self.scripting and tag == "noscript": | ||
| self.set_cdata_mode(tag) | ||
| elif tag == "plaintext": | ||
| self.set_cdata_mode(tag) | ||
| self.interesting = re.compile(r'\z') | ||
|
||
| return endpos | ||
|
|
||
| # Internal -- check to see if we have a complete starttag; return end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add support of the "plaintext" element, RAWTEXT elements "xmp", "iframe", | ||
| "noembed" and "noframes", and optionally RAWTEXT element "noscript" in | ||
| :class:`html.parser.HTMLParser`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated now that the list has been expanded.
It might be easier to have a short section about parsing modes, listing each mode, which elements trigger it, whether charrefs are converted or not, and when the state is terminated.
Here we could then say
with
RAWTEXTlinking to that section.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to document this here? This is a part of the HTML5 specification. What will the user get from this information?