Skip to content

Commit

Permalink
(fix) case sensitive script/style snipping (#200)
Browse files Browse the repository at this point in the history
Fixes #198
  • Loading branch information
dummdidumm authored Feb 3, 2021
1 parent 014b63f commit 911b655
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.1.2 (Unreleased)

* Keep whitespace around script/style tags ([#197](https://github.com/sveltejs/prettier-plugin-svelte/issues/197))
* Make script/style tag snipping case sensitive ([#198](https://github.com/sveltejs/prettier-plugin-svelte/issues/198))

## 2.1.1

Expand Down
2 changes: 1 addition & 1 deletion src/lib/snipTagContent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const snippedTagContentAttribute = '✂prettier:content✂';

export function snipTagContent(tagName: string, source: string, placeholder = ''): string {
const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'gi');
const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'g');
return source.replace(regex, (_, attributes, content) => {
const encodedContent = Buffer.from(content).toString('base64');
return `<${tagName}${attributes} ${snippedTagContentAttribute}="${encodedContent}">${placeholder}</${tagName}>`;
Expand Down
10 changes: 10 additions & 0 deletions test/printer/samples/component-style-script-tagname.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script></script>

<Script />
<Script>hello</Script>
<ScriptedContent />
<StyledText />
<Style />
<Style>hello</Style>

<style></style>

0 comments on commit 911b655

Please sign in to comment.