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

[clipboard api] reformat function seems to be restrictive #50744

Closed
karlcow opened this issue Feb 17, 2025 · 0 comments · Fixed by #50746
Closed

[clipboard api] reformat function seems to be restrictive #50744

karlcow opened this issue Feb 17, 2025 · 0 comments · Fixed by #50746

Comments

@karlcow
Copy link
Contributor

karlcow commented Feb 17, 2025

function reformatHtml(html) {
const parser = new DOMParser();
const htmlString =
parser.parseFromString(html, 'text/html').documentElement.innerHTML;
const reformattedString = htmlString.replace(/\>\s*\</g, '> <');
return reformattedString;
}

Currently all browsers return something different, but it fails on what should the be the serialization. The current result is aligned with Firefox result only. It's probably too restrictive.

  • FAIL Safari returns <head> </head> <body> <p style=\"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;\">Hello World</p> </body>
  • PASS Firefox returns <head> <title>Title of the document</title> </head> <body> <p>Hello World</p> </body>
  • FAIL Chrome returns <head> <title>Title of the\n document</title> </head> <body> <p>Hello World</p> </body>

The specification doesn't seem to have a canonical form requirement.

The test should probably check only that <p>Hello World</p> has been copied.
Which is basically the visible content for the user, the rest seems to be implementation details.

What do you think @saschanaz?
I can probably make a PR in that sense?

karlcow added a commit that referenced this issue Feb 17, 2025
Fix #50744
The specification doesn't have the definition of a canonical form. When writing html through `.write()` we should be able to carry the information which is visible to users. 

This should level the playing field in between browsers with their different styles of building HTML during read/write operation of the clipboard API.
karlcow added a commit that referenced this issue Feb 21, 2025
Fix #50744
The specification doesn't have the definition of a canonical form. When writing html through `.write()` we should be able to carry the information which is visible to users.

This should level the playing field in between browsers with their different styles of building HTML during read/write operation of the clipboard API.
karlcow added a commit that referenced this issue Feb 21, 2025
The specification doesn't have the definition of a canonical form. When writing html through `.write()` we should be able to carry the information which is visible to users. 

This should level the playing field in between browsers with their different styles of building HTML during read/write operation of the clipboard API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@karlcow and others