Skip to content

Commit

Permalink
Cache another regex
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Oct 13, 2024
1 parent 66e8bfe commit f85cf22
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/enhance-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const INLINE_CODE_REGEX = /`[^`]+`/;
const TWITTER_DOMAIN_REGEX = /(twitter|x)\.com/i;
const TWITTER_MENTION_REGEX = /@[a-zA-Z0-9_]+@(twitter|x)\.com/;
const TWITTER_MENTION_CAPTURE_REGEX = /(@([a-zA-Z0-9_]+)@(twitter|x)\.com)/g;
const CODE_INLINE_CAPTURE_REGEX = /(`[^]+?`)/g;

function createDOM(html, isDocumentFragment) {
if (isDocumentFragment) {
Expand Down Expand Up @@ -197,7 +198,7 @@ function _enhanceContent(content, opts = {}) {
for (const node of textNodes) {
let html = escapeHTML(node.nodeValue);
if (INLINE_CODE_REGEX.test(html)) {
html = html.replaceAll(/(`[^]+?`)/g, '<code>$1</code>');
html = html.replaceAll(CODE_INLINE_CAPTURE_REGEX, '<code>$1</code>');
}
fauxDiv.innerHTML = html;
// const nodes = [...fauxDiv.childNodes];
Expand Down

0 comments on commit f85cf22

Please sign in to comment.