-
Notifications
You must be signed in to change notification settings - Fork 78
Fix: Support HTML <selectedcontent>
element
#1101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jp-knj
wants to merge
3
commits into
withastro:main
Choose a base branch
from
jp-knj:fix-issue-1093
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@astrojs/compiler": minor | ||
--- | ||
|
||
Support HTML <selectedcontent> element | ||
|
||
Based on the recent commit history, this change appears to be related to fixing issue #1093 regarding selectedcontent parsing in customizable selects. The <selectedcontent> element is part of the new Customizable Select Element API | ||
in HTML, used within <selectlist> elements to display the currently selected option(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1418,6 +1418,14 @@ func inBodyIM(p *parser) bool { | |
return true | ||
} | ||
default: | ||
// Special handling for selectedcontent as a void element | ||
if p.tok.Data == "selectedcontent" { | ||
p.reconstructActiveFormattingElements() | ||
p.addElement() | ||
p.oe.pop() | ||
p.acknowledgeSelfClosingTag() | ||
return true | ||
} | ||
p.reconstructActiveFormattingElements() | ||
p.addElement() | ||
if p.hasSelfClosingToken { | ||
|
@@ -1436,6 +1444,12 @@ func inBodyIM(p *parser) bool { | |
return true | ||
} | ||
|
||
// Special handling for selectedcontent end tag - just ignore it | ||
// since it's treated as a void element | ||
if p.tok.Data == "selectedcontent" { | ||
return true | ||
} | ||
|
||
switch p.tok.DataAtom { | ||
case a.Body: | ||
p.addLoc() | ||
|
@@ -2319,6 +2333,19 @@ func inSelectIM(p *parser) bool { | |
p.resetInsertionMode() | ||
case a.Template: | ||
return inHeadIM(p) | ||
default: | ||
// Handle closing tags for elements that are allowed in customizable select | ||
// (like button for the new HTML select element) | ||
if p.tok.Data == "button" { | ||
// Close the button if it's open | ||
for i := len(p.oe) - 1; i >= 0; i-- { | ||
if p.oe[i].Data == "button" { | ||
p.oe = p.oe[:i] | ||
break | ||
} | ||
} | ||
return true | ||
} | ||
Comment on lines
+2337
to
+2348
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why support
|
||
} | ||
case CommentToken: | ||
p.addChild(&Node{ | ||
|
40 changes: 40 additions & 0 deletions
40
internal/printer/__printer_js__/selectedcontent_element_in_customizable_select.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[TestPrinter/selectedcontent_element_in_customizable_select - 1] | ||
## Input | ||
|
||
``` | ||
<select><button><selectedcontent></selectedcontent></button><option>Option 1</option><option>Option 2</option></select> | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
||
const $$Component = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent></button><option>Option 1</option><option>Option 2</option></select>`; | ||
}, undefined, undefined); | ||
export default $$Component; | ||
``` | ||
--- |
40 changes: 40 additions & 0 deletions
40
internal/printer/__printer_js__/selectedcontent_self-closing_element.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[TestPrinter/selectedcontent_self-closing_element - 1] | ||
## Input | ||
|
||
``` | ||
<select><button><selectedcontent /></button><option>Option 1</option><option>Option 2</option></select> | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
||
const $$Component = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent></button><option>Option 1</option><option>Option 2</option></select>`; | ||
}, undefined, undefined); | ||
export default $$Component; | ||
``` | ||
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -820,19 +820,20 @@ func render1(p *printer, n *Node, opts RenderOptions) { | |
// are those that can't have any contents. | ||
// nolint | ||
var voidElements = map[string]bool{ | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility. | ||
"link": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true, | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility. | ||
"link": true, | ||
"meta": true, | ||
"param": true, | ||
"selectedcontent": true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just add selectedcontent, then apply formatting |
||
"source": true, | ||
"track": true, | ||
"wbr": true, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Ignore End Tags
The Problem Flow:
When HTML contains
<selectedcontent></selectedcontent>
:<selectedcontent>
→ StartTagToken</selectedcontent>
→ EndTagTokenWhat Actually Happened: