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

Don't escape the text content in style #21

Closed
4 tasks done
wqcstrong opened this issue May 27, 2023 · 4 comments · Fixed by #22
Closed
4 tasks done

Don't escape the text content in style #21

wqcstrong opened this issue May 27, 2023 · 4 comments · Fixed by #22
Labels
💪 phase/solved Post is done

Comments

@wqcstrong
Copy link

Initial checklist

Problem

import rehypeDomParse from 'rehype-dom-parse';
import rehypeDomStrigify from 'rehype-dom-stringify';

const htmlString = `
<style>
  body > div {
    width: 100px;
  }
</style>
`;

console.log(
  unified()
    .use(rehypeDomParse)
    .use(rehypeDomStrigify)
    .processSync(htmlString)
    .toString(),
);

Actually output:

<style>
  body &gt; div {
    width: 100px;
  }
</style>

Solution

Expected output:

<style>
  body > div {
    width: 100px;
  }
</style>

Alternatives

/

@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
@wooorm
Copy link
Member

wooorm commented May 27, 2023

Hmm, yeah, bug.
You can try this in a browser. It a) should show the style in red text, b) shows that it’s the XMLSerializer that does this:

document.body.innerHTML = `<style>
  body > style {
    display: block; color: red;
  }
</style>`;
console.log(document.body.innerHTML)
new XMLSerializer().serializeToString(document.body)

@wooorm
Copy link
Member

wooorm commented May 27, 2023

I have a PR, could you check it?

@wqcstrong
Copy link
Author

😁 I have just reviewd the core implement

Thanks for your job, bro!

@wooorm wooorm closed this as completed in #22 Sep 4, 2023
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Sep 4, 2023
@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
Development

Successfully merging a pull request may close this issue.

2 participants