Skip to content

Commit 563daf1

Browse files
committed
wip
1 parent c53f33f commit 563daf1

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

internal/parser.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,12 @@ func inBodyIM(p *parser) bool {
14441444
return true
14451445
}
14461446

1447+
// Special handling for selectedcontent end tag - just ignore it
1448+
// since it's treated as a void element
1449+
if p.tok.Data == "selectedcontent" {
1450+
return true
1451+
}
1452+
14471453
switch p.tok.DataAtom {
14481454
case a.Body:
14491455
p.addLoc()
@@ -2327,6 +2333,19 @@ func inSelectIM(p *parser) bool {
23272333
p.resetInsertionMode()
23282334
case a.Template:
23292335
return inHeadIM(p)
2336+
default:
2337+
// Handle closing tags for elements that are allowed in customizable select
2338+
// (like button for the new HTML select element)
2339+
if p.tok.Data == "button" {
2340+
// Close the button if it's open
2341+
for i := len(p.oe) - 1; i >= 0; i-- {
2342+
if p.oe[i].Data == "button" {
2343+
p.oe = p.oe[:i]
2344+
break
2345+
}
2346+
}
2347+
return true
2348+
}
23302349
}
23312350
case CommentToken:
23322351
p.addChild(&Node{

internal/printer/__printer_js__/selectedcontent_element_in_customizable_select.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydra
3333
3434
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
3535
36-
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent><option>Option 1</option><option>Option 2</option></button></select>`;
36+
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent></button><option>Option 1</option><option>Option 2</option></select>`;
3737
}, undefined, undefined);
3838
export default $$Component;
3939
```
40-
---
40+
---

internal/printer/__printer_js__/selectedcontent_self-closing_element.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydra
3333
3434
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
3535
36-
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent><option>Option 1</option><option>Option 2</option></button></select>`;
36+
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent></button><option>Option 1</option><option>Option 2</option></select>`;
3737
}, undefined, undefined);
3838
export default $$Component;
3939
```
40-
---
40+
---

internal/token.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,12 +1211,18 @@ func (z *Tokenizer) readStartTag() TokenType {
12111211
}
12121212

12131213
// HTML void tags list: https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#syntax-elements
1214-
// Also look for a self-closing token thats not in the list (e.g. "<svg><path/></svg>")
1215-
if z.startTagIn("area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "selectedcontent", "source", "track", "wbr") || z.err == nil && z.buf[z.raw.End-2] == '/' {
1214+
// Also look for a self-closing token that's not in the list (e.g. "<svg><path/></svg>")
1215+
if z.startTagIn("area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr") || z.err == nil && z.buf[z.raw.End-2] == '/' {
12161216
// Reset tokenizer state for self-closing elements
12171217
z.rawTag = ""
12181218
return SelfClosingTagToken
12191219
}
1220+
// Special handling for selectedcontent - it's void but can have a closing tag in HTML
1221+
if z.startTagIn("selectedcontent") && z.err == nil && z.buf[z.raw.End-2] == '/' {
1222+
// Only treat as self-closing if it actually has />
1223+
z.rawTag = ""
1224+
return SelfClosingTagToken
1225+
}
12201226

12211227
// Handle TypeScript Generics
12221228
if len(z.expressionElementStack) > 0 && len(z.expressionElementStack[len(z.expressionElementStack)-1]) == 0 {

internal/token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func TestBasic(t *testing.T) {
418418
{
419419
"selectedcontent element",
420420
`<select><button><selectedcontent></selectedcontent></button><option>A</option></select>`,
421-
[]TokenType{StartTagToken, StartTagToken, SelfClosingTagToken, EndTagToken, EndTagToken, StartTagToken, TextToken, EndTagToken, EndTagToken},
421+
[]TokenType{StartTagToken, StartTagToken, StartTagToken, EndTagToken, EndTagToken, StartTagToken, TextToken, EndTagToken, EndTagToken},
422422
},
423423
{
424424
"selectedcontent self-closing",

0 commit comments

Comments
 (0)