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

fix: fix entity specs #2652

Merged
merged 2 commits into from Nov 20, 2022
Merged

fix: fix entity specs #2652

merged 2 commits into from Nov 20, 2022

Conversation

UziTech
Copy link
Member

@UziTech UziTech commented Nov 12, 2022

Marked version: 4.2.2

Description

Fix Entity and numeric character references specs #28 and #34.

In order to fix the last 2 Entity and numeric character references specs we would need to convert html entities to percent encoded with this json map: https://html.spec.whatwg.org/entities.json. This would increase the size of marked significantly (almost double 48k -> 84k) and provide very little benefit to the actual output.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Nov 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
marked-website ✅ Ready (Inspect) Visit Preview Nov 12, 2022 at 8:05PM (UTC)

src/helpers.js Fixed Show fixed Hide fixed
@calculuschild
Copy link
Contributor

Is there really no built-in JS function to convert html entities?

@UziTech
Copy link
Member Author

UziTech commented Nov 13, 2022

Unfortunately no. The reason given is because they are HTML entities not JavaScript entities. 🫤

There is an easy way to convert them if you have a DOM available but NodeJS doesn't have a DOM so it wouldn't always be available.

And since they are automatically converted by the browser the broken tests don't mean anything is actually broken in marked, just that the output looks different.

@UziTech
Copy link
Member Author

UziTech commented Nov 19, 2022

Any objections to merging this?

@styfle
Copy link
Member

styfle commented Nov 20, 2022

This would increase the size of marked significantly (almost double 48k -> 84k)

That would be unfortunate. Perhaps we could add the most common ones to escapeReplacements?

@@ -170,7 +170,7 @@ export class Renderer {
if (href === null) {
return text;
}
let out = '<a href="' + escape(href) + '"';
let out = '<a href="' + href + '"';
Copy link
Member

Choose a reason for hiding this comment

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

What about when href contains a ' or "?

Do we have a test for that?

Copy link
Member Author

@UziTech UziTech Nov 20, 2022

Choose a reason for hiding this comment

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

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks!

@UziTech UziTech merged commit 36a2b63 into markedjs:master Nov 20, 2022
@UziTech UziTech deleted the encode-entity branch November 20, 2022 16:05
github-actions bot pushed a commit that referenced this pull request Nov 20, 2022
## [4.2.3](v4.2.2...v4.2.3) (2022-11-20)

### Bug Fixes

* fix entity specs ([#2652](#2652)) ([36a2b63](36a2b63))
* fix link reference definitions specs ([#2654](#2654)) ([b7eea95](b7eea95))
* fix marked.use with multiple args ([#2651](#2651)) ([73a7bf5](73a7bf5))
* fix multiline setext headings ([#2655](#2655)) ([4aee878](4aee878))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants