Skip to content
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

Change to serialize as HTML instead of XML #22

Merged
merged 3 commits into from
Sep 4, 2023
Merged

Change to serialize as HTML instead of XML #22

merged 3 commits into from
Sep 4, 2023

Conversation

wooorm
Copy link
Member

@wooorm wooorm commented May 27, 2023

Closes GH-21.

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

This switches from the DOMs XMLSerializer to manually using DOM node’s APIs to serialize as HTML.
That is because the XML syntax is not always compatible with the HTML syntax.
However, it is a significant, breaking, change.

Closes GH-21.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 27, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (6d41f5f) 100.00% compared to head (aaae592) 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #22   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          102       129   +27     
=========================================
+ Hits           102       129   +27     
Impacted Files Coverage Δ
packages/rehype-dom-stringify/lib/index.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

test.js Outdated
@@ -93,10 +92,25 @@ test('parse', async (t) => {
.data('settings', {fragment: false})
.processSync('<title>Hi</title><h2>Hello world!')
.toString(),
'<html><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what jsdom does: I don’t see it happening (document.documentElement.outerHTML printing an xmlns) in safari

Copy link

@wqcstrong wqcstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

@ChristianMurphy ChristianMurphy added the 🧑 semver/major This is a change label May 27, 2023
// Comment, text, fragment.
if ('textContent' in node) {
const div = document.createElement('div')
div.append(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this set innerText in case the content has tag-like text?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The textContent isn't actually used! Both that field and innerText should exist together AFAIK

But, I think we don't need this check, we can make a div (or template per remco's Q), and append to it, for any remaining node in the last case (text, comment, or fragment)

@wooorm wooorm merged commit 8ab866e into main Sep 4, 2023
4 checks passed
@wooorm wooorm deleted the serialize-html branch September 4, 2023 08:24
@wooorm wooorm added the 💪 phase/solved Post is done label Sep 4, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🧑 semver/major This is a change
Development

Successfully merging this pull request may close these issues.

Don't escape the text content in style
5 participants