|
4 | 4 | const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
5 | 5 |
|
6 | 6 | // See https://regexr.com/6p8p0
|
7 |
| -const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<value1>[\s\S]*?)\3|(?<value2>[^\s>]+))))/g |
| 7 | +const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g |
8 | 8 | // ^ capture group 1: boolean attribute name (attributes without values)
|
9 |
| -// ^ capture group 2: non-boolean attribue name |
10 |
| -// ^ capture group 4: non-boolean attribue value with quotes |
11 |
| -// ^ capture group 5: non-boolean attribue value without quotes |
| 9 | +// ^ capture group 2: non-boolean attribute name |
| 10 | +// ^ capture group 4: non-boolean attribute value with quotes |
| 11 | +// ^ capture group 5: non-boolean attribute value without quotes |
12 | 12 | // TODO
|
13 | 13 | // - "/" values in the middle of the HTML tag (they don't self-close the element, but skipped)
|
14 | 14 | // - What other cases?
|
@@ -61,15 +61,10 @@ function parseTag(/**@type {string}*/tag) {
|
61 | 61 | }
|
62 | 62 | }
|
63 | 63 | }
|
64 |
| - const reg = new RegExp(attrRE) |
65 |
| - const matches = tag.matchAll(reg) |
66 |
| - const matchesArray = Array.from(matches) |
67 | 64 |
|
68 |
| - // for (const match of matches) { |
69 |
| - // for (const match of matchesArray) { |
70 |
| - for (let i = 0, l = matchesArray.length; i < l; i += 1) { |
71 |
| - const match = matchesArray[i] |
| 65 | + const reg = new RegExp(attrRE) |
72 | 66 |
|
| 67 | + for (const match of tag.matchAll(reg)) { |
73 | 68 | // TODO named groups method not working yet, groups is undefined in tests (maybe not out in Node.js yet)
|
74 | 69 | // const groups = match.groups
|
75 | 70 | // res.attrs[groups.boolean || groups.name] = groups.value1 || groups.value2 || ""
|
|
0 commit comments