`)
e := NewHTMLExtractor()
result, err := e.Extract("index.html", src)
require.NoError(t, err)
// id-anchored elements are DocSection (KindDoc) nodes now, not KindVariable.
docs := nodesOfKind(result.Nodes, graph.KindDoc)
byName := map[string]*graph.Node{}
for _, n := range docs {
byName[n.Name] = n
}
require.Contains(t, byName, "#main-content")
assert.Equal(t, "index.html::doc:#main-content", byName["#main-content"].ID)
assert.Equal(t, "Hello world", byName["#main-content"].Meta["section_text"])
assert.Equal(t, true, byName["#main-content"].Meta["html_anchor"])
assert.Contains(t, byName, "#login-form")
assert.Contains(t, byName, "#username")
// No id anchors should leak out as the old KindVariable shape.
assert.Empty(t, nodesOfKind(result.Nodes, graph.KindVariable))
}
func TestHTMLExtractor_InlineScript(t *testing.T) {
src := []byte(`
`)
e := NewHTMLExtractor()
result, err := e.Extract("page.html", src)
require.NoError(t, err)
// The inline JS function is extracted and owned by the HTML file.
var greet *graph.Node
for _, n := range result.Nodes {
if n.Kind == graph.KindFunction && n.Name == "greet" {
greet = n
}
}
require.NotNil(t, greet, "inline