From 2ebb9620a4823eb6e5b81732c8a9a97d8e8991bd Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Fri, 7 Feb 2025 16:43:01 +0100 Subject: [PATCH] fix bug, when text content contains < --- src/parse.js | 43 +++++++++++++++++++++++++--- test/parse.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 5 deletions(-) diff --git a/src/parse.js b/src/parse.js index 8caaf64..d8ea651 100644 --- a/src/parse.js +++ b/src/parse.js @@ -24,7 +24,23 @@ export default function parse(html, options) { }) } - html.replace(tagRE, function (tag, index) { + const matches = Array.from(html.matchAll(tagRE)) + matches.forEach(function (match, i) { + const tag = match[0] + if (!tag) return console.log({ html, matches }) + const amountOfLts = tag.split('<').length + const amountOfGts = tag.split('>').length + if (amountOfLts > 0 && amountOfLts > amountOfGts) { + const firstPart = tag.substring(0, tag.indexOf('<', tag.indexOf('<') + 1)) + const secondPart = tag.substring(firstPart.length) + matches[i][0] = secondPart + matches[i].index += firstPart.length + } + }) + matches.forEach(function (match, i) { + const tag = match[0] + if (!tag) return + const index = match.index if (inComponent) { if (tag !== '') { return @@ -36,6 +52,13 @@ export default function parse(html, options) { const isComment = tag.startsWith('