From 82163c0b88ae69638798e2f443a09b79e6d11ad8 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 13 Oct 2024 11:28:54 +0800 Subject: [PATCH] Fix text nodes extraction fails on template element --- src/utils/enhance-content.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js index fc048169..bbb2b840 100644 --- a/src/utils/enhance-content.js +++ b/src/utils/enhance-content.js @@ -30,9 +30,15 @@ const TWITTER_MENTION_REGEX = /@[a-zA-Z0-9_]+@(twitter|x)\.com/; const TWITTER_MENTION_CAPTURE_REGEX = /(@([a-zA-Z0-9_]+)@(twitter|x)\.com)/g; function createDOM(html, isDocumentFragment) { - const tpl = document.createElement('template'); - tpl.innerHTML = html; - return isDocumentFragment ? tpl.content : tpl; + if (isDocumentFragment) { + const tpl = document.createElement('template'); + tpl.innerHTML = html; + return tpl.content; + } else { + const tpl = document.createElement('div'); + tpl.innerHTML = html; + return tpl; + } } function _enhanceContent(content, opts = {}) {