-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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 initial content for setHTMLUnsafe and parseHTMLUnsafe #33492
Conversation
Preview URLs (7 pages)Flaws (10)Note! 4 documents with no flaws that don't need to be listed. 🎉 URL:
URL:
URL:
(comment last updated: 2024-05-24 00:03:38) |
bb449b6
to
3c3685b
Compare
26ce834
to
6e530e5
Compare
|
||
{{APIRef("DOM")}}{{SeeCompatTable}} | ||
|
||
The **`setHTMLUnsafe()`** method of the {{domxref("Element")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the element. |
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.
- "insert it into" has unclear semantics - could mean append, or replace, or perhaps something else. Should be something like "replaces the target element's subtree".
- There are lots of ways to set HTML in an element, so why is this one special? I'd explain that and link to alternatives. When do you use this one? Why does it need to exist? Why can't I just set innerHTML?
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.
Ditto for the shadow root.
|
||
The code below demonstrates how to parse a string of HTML and insert it into the `Element` with an id of `target`. | ||
|
||
```js |
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.
I would make this a live example.
|
||
{{APIRef("DOM")}}{{SeeCompatTable}} | ||
|
||
The **`setHTMLUnsafe()`** method of the {{domxref("ShadowRoot")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the shadow root. |
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.
Same comments as for the element version
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.
If there are any differences in semantics compared to the element version we should capture those.
### Exceptions | ||
|
||
None. | ||
|
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.
It would be nice to have a live example, though not a "have to".
## Syntax | ||
|
||
```js-nolint | ||
const doc = Document.parseHTMLUnsafe(input) |
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.
Here we can keep Document
(I think)
const doc = Document.parseHTMLUnsafe(input) | |
Document.parseHTMLUnsafe(html) |
@lukewarlow I think this is just a little too minimal. We need to at least explain why these exist and properly cross link. Live examples are optional (I love them). FYI MDN has a PR acceptance rule that essentially says new stuff has to be of a pretty high standard, whereas, if you are updating existing stuff the bar is "an improvement". I don't think there is a lot of work here if the reason for these to exist is known. |
I'll go through these comments and address them later today. |
@lukewarlow I think you may have run out of time to do this on that day :-). I might have a go at this on Monday or Tuesday if you don't - now mfreed has answered our questions it's a lot more clear how this works. Note that I'm doing cross linking to some of these methods in #33600 |
@lukewarlow I've updated this to reflect the comments. Can you and @Elchi3 sanity check/review this? Note, I am likely to add some live examples for the methods on Friday, but might do that on a new PR. |
LGTM other than that suggestion. Apologies I didn't find time to get back to this. |
@lukewarlow I merged your suggestions. Thanks for the review. No need to apologize - really appreciate you kicking this off. If you can though, it is often good to add a short note that you have run out of time and you're happy for other people to take it forward (assuming you are). |
Co-authored-by: Luke Warlow <[email protected]>
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.
Merging. Any follow on changes should be done in a new PR.
Description
Adds basic pages for setHTMLUnsafe and parseHTMLUnsafe.
Motivation
These functions are recently shipping across the board and there's no indication of their existence on MDN.
Additional details
Related issues and pull requests
Relates to #32731