Manual code review by an actual human.
This commit is contained in:
@@ -7,9 +7,8 @@ import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
// GetClasses extracts CSS classes from an HTML node
|
||||
func GetClasses(node *html.Node) []string {
|
||||
classAttr := getAttribute(node, "class")
|
||||
classAttr := GetAttribute(node, "class")
|
||||
if classAttr == "" {
|
||||
return []string{}
|
||||
}
|
||||
@@ -23,8 +22,8 @@ func ContainsClass(classes []string, target string) bool {
|
||||
return slices.Contains(classes, target)
|
||||
}
|
||||
|
||||
// getAttribute gets an attribute value from an HTML node
|
||||
func getAttribute(node *html.Node, key string) string {
|
||||
// GetAttribute gets an attribute value from an HTML node
|
||||
func GetAttribute(node *html.Node, key string) string {
|
||||
for _, attr := range node.Attr {
|
||||
if attr.Key == key {
|
||||
return attr.Val
|
||||
@@ -76,9 +75,9 @@ var blockingElements = map[string]bool{
|
||||
"dl": true,
|
||||
}
|
||||
|
||||
// hasEditableContent checks if a node contains content that can be safely edited
|
||||
// HasEditableContent checks if a node contains content that can be safely edited
|
||||
// This includes text and safe inline formatting elements
|
||||
func hasEditableContent(node *html.Node) bool {
|
||||
func HasEditableContent(node *html.Node) bool {
|
||||
if node.Type != html.ElementNode {
|
||||
return false
|
||||
}
|
||||
@@ -129,16 +128,15 @@ func isContainer(node *html.Node) bool {
|
||||
"main": true,
|
||||
"aside": true,
|
||||
"nav": true,
|
||||
"ul": true, // Phase 3: Lists are containers
|
||||
"ul": true,
|
||||
"ol": true,
|
||||
}
|
||||
|
||||
return containerTags[node.Data]
|
||||
}
|
||||
|
||||
// findViableChildren finds all descendant elements that should get .insertr class
|
||||
// Phase 3: Recursive traversal with block/inline classification and boundary respect
|
||||
func findViableChildren(node *html.Node) []*html.Node {
|
||||
// FindViableChildren finds all descendant elements that should get .insertr class
|
||||
func FindViableChildren(node *html.Node) []*html.Node {
|
||||
var viable []*html.Node
|
||||
traverseForViableElements(node, &viable)
|
||||
return viable
|
||||
@@ -266,12 +264,7 @@ func isDeferredElement(node *html.Node) bool {
|
||||
// hasInsertrClass checks if node has class="insertr"
|
||||
func hasInsertrClass(node *html.Node) bool {
|
||||
classes := GetClasses(node)
|
||||
for _, class := range classes {
|
||||
if class == "insertr" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(classes, "insertr")
|
||||
}
|
||||
|
||||
// isSelfClosing checks if an element is typically self-closing
|
||||
@@ -331,23 +324,6 @@ func findElementWithContent(node *html.Node, targetTag, targetContent string) *h
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAttribute gets an attribute value from an HTML node (exported version)
|
||||
func GetAttribute(node *html.Node, key string) string {
|
||||
return getAttribute(node, key)
|
||||
}
|
||||
|
||||
// HasEditableContent checks if a node has editable content (exported version)
|
||||
func HasEditableContent(node *html.Node) bool {
|
||||
return hasEditableContent(node)
|
||||
}
|
||||
|
||||
// FindViableChildren finds viable children for editing (exported version)
|
||||
func FindViableChildren(node *html.Node) []*html.Node {
|
||||
return findViableChildren(node)
|
||||
}
|
||||
|
||||
// Text extraction utility functions
|
||||
|
||||
// ExtractTextContent extracts all text content from an HTML node recursively
|
||||
func ExtractTextContent(node *html.Node) string {
|
||||
var text strings.Builder
|
||||
@@ -355,7 +331,6 @@ func ExtractTextContent(node *html.Node) string {
|
||||
return strings.TrimSpace(text.String())
|
||||
}
|
||||
|
||||
// extractTextRecursiveUnified is the internal unified implementation
|
||||
func extractTextRecursiveUnified(node *html.Node, text *strings.Builder) {
|
||||
if node.Type == html.TextNode {
|
||||
text.WriteString(node.Data)
|
||||
|
||||
Reference in New Issue
Block a user