From a4413724b2b52943c11178f826c5a3e7be29850f Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 23 Apr 2021 18:23:32 +0200 Subject: [PATCH] (fix) adjust snip regex (#216) Account for the script/style being inside a comment Fixes #212 --- src/lib/snipTagContent.ts | 7 +++++-- .../samples/style-script-commented-out.html | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/printer/samples/style-script-commented-out.html diff --git a/src/lib/snipTagContent.ts b/src/lib/snipTagContent.ts index 0f8d1190..b61757af 100644 --- a/src/lib/snipTagContent.ts +++ b/src/lib/snipTagContent.ts @@ -1,8 +1,11 @@ export const snippedTagContentAttribute = '✂prettier:content✂'; export function snipTagContent(tagName: string, source: string, placeholder = ''): string { - const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'g'); - return source.replace(regex, (_, attributes, content) => { + const regex = new RegExp(`|<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'g'); + return source.replace(regex, (match, attributes, content) => { + if (match.startsWith(' + + + +