Skip to content

Commit 1c4bcfe

Browse files
committed
fix: handle > tags in attributes
related to sveltejs/language-tools#2204
1 parent 66ec48b commit 1c4bcfe

File tree

6 files changed

+257
-15
lines changed

6 files changed

+257
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# prettier-plugin-svelte changelog
22

3+
## 3.1.2
4+
5+
- (fix) handle `>` tags in attributes
6+
37
## 3.1.1
48

59
- (fix) handle types on each/await contexts

package-lock.json

Lines changed: 228 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-svelte",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "Svelte plugin for prettier",
55
"main": "plugin.js",
66
"files": [
@@ -44,7 +44,7 @@
4444
"prettier": "^3.0.0",
4545
"rollup": "2.36.0",
4646
"rollup-plugin-typescript": "1.0.1",
47-
"svelte": "^3.57.0",
47+
"svelte": "^4.2.7",
4848
"ts-node": "^10.1.1",
4949
"tslib": "^2.6.0",
5050
"typescript": "5.1.3"

src/lib/extractAttributes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { AttributeNode, TextNode } from '../print/nodes';
22

3-
export function extractAttributes(html: string): AttributeNode[] {
4-
const extractAttributesRegex = /<[a-z]+[\s\n]*([\s\S]*?)>/im;
5-
const attributeRegex = /([^\s=]+)(?:=(?:(?:("|')([\s\S]*?)\2)|(?:(\S+?)(?:\s|>|$))))?/gim;
3+
const extractAttributesRegex =
4+
/<[a-z]+((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>/im;
5+
const attributeRegex = /([^\s=]+)(?:=(?:(?:("|')([\s\S]*?)\2)|(?:([^>\s]+?)(?:\s|>|$))))?/gim;
66

7+
export function extractAttributes(html: string): AttributeNode[] {
78
const [, attributesString] = html.match(extractAttributesRegex)!;
89

910
const attrs: AttributeNode[] = [];

0 commit comments

Comments
 (0)