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

chore: use tiny-decode instead of v-html+escapeHtml #108

Merged
merged 1 commit into from
May 23, 2024
Merged

Conversation

brc-dd
Copy link
Member

@brc-dd brc-dd commented May 22, 2024

fixes the concerns in #106

/cc @Jinjiang you can try something like this in demo/guide/introduction.md to test:

## What &amp; &#123;&#123; &lt;script&gt; (1) &#125;&#125; \<script setup> is Vue.js?

The browser bundle only has this code (<200B after gzip/br):

const n=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});?/gi;let t;function o(e){return t||(t=new DOMParser),t.parseFromString(e,"text/html").documentElement.textContent}function c(e){return n.lastIndex=0,e.replace(n,r=>o(r))

unminified:

const ENTITY_RE = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});?/gi;
let p;
function decodeHTML5(value) {
  if (!p)
    p = new DOMParser();
  return p.parseFromString(value, "text/html").documentElement.textContent;
}
function decode(value) {
  ENTITY_RE.lastIndex = 0;
  return value.replace(ENTITY_RE, (m) => decodeHTML5(m));
}

@brc-dd brc-dd requested a review from Jinjiang May 22, 2024 08:39
@Jinjiang Jinjiang merged commit 01627f9 into main May 23, 2024
5 checks passed
@Jinjiang Jinjiang deleted the better-decoding branch May 23, 2024 14:06
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.

2 participants