-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: x/net/html: add PrependChild and InsertAfter to Node #46960
Comments
Can you give a short example showing when a program would want to use these new methods? Thanks. |
Sure. I am writing a static site generator which renders pages by combining a layout HTML file with HTML files containing the content of each page. The repetitive parts of the pages reside in the layout file and the unique content are in the content files. The content files start with a front-matter containing metadata about the page, such as its title and description. For example if we have the content page <!--{
"title": "The title of the page",
"description": "Page description"
}-->
<p>here is a paragraph</p>
<h2>And a subheading</h2>
<p>And another paragraph</p> the program would first insert all elements after the front-matter into the layout. It would then insert a // Insert the page title heading
pageTitle := &html.Node{
Type: html.ElementNode,
Data: "h1",
DataAtom: atom.H1,
}
pageTitle.AppendChild(&html.Node{
Type: html.TextNode,
Data: titleFieldInFrontMatter,
})
main.PrependChild(pageTitle)
// Insert the page description paragraph
pageDescription := &html.Node{
Type: html.ElementNode,
Data: "p",
DataAtom: atom.P,
}
pageDescription.AppendChild(&html.Node{
Type: html.TextNode,
Data: descriptionFieldInFrontMatter,
})
pageTitle.Parent.InsertAfter(pageDescription, pageTitle) Sorry, this did not turn out short after all :D |
/cc @nigeltao |
This proposal has been added to the active column of the proposals project |
The methods that are already there - AppendChild and InsertBefore - are a complete set in the sense that they provide all possible functionality. Do we really need to add a second complete set? Also, if your program finds that it needs these frequently, it is easy to write them as local helper functions, either using AppendChild and InsertBefore or using direct manipulation of the Nodes. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
I have already made a PR, but @neild said I should create a proposal.
The following is the commit message of the commit in my PR:
The text was updated successfully, but these errors were encountered: