Private Sub ParseAttributes (Parent As HtmlNode)
Dim start As Int = Index
ReadUntil(">")
Dim s As String = mHtml.SubString2(start, Index - 1)
' Parse attributes with values (key="value" or key='value')
For Each EscapeChar As String In Array("'", QUOTE)
Dim m As Matcher = Regex.Matcher($"([a-zA-Z0-9-]+)\s*=\s*\${EscapeChar}([^${EscapeChar}]+)\${EscapeChar}"$, s)
Do While m.Find
Parent.Attributes.Add(CreateHtmlAttribute(m.Group(1), m.Group(2)))
Loop
Next
' Parse boolean attributes (standalone keys like "disabled", "selected", "required")
' More precise regex to avoid matching class values
Dim m As Matcher = Regex.Matcher($"\b([a-zA-Z0-9-]+)(?=\s*[/>]|\s*$)"$, s)
Do While m.Find
Dim attrName As String = m.Group(1)
' Skip if this is part of a key=value pair (already processed above)
Dim isAlreadyProcessed As Boolean = False
For Each existingAttr As HtmlAttribute In Parent.Attributes
If existingAttr.Key = attrName Then
isAlreadyProcessed = True
Exit
End If
Next
' Also check if this might be part of a class value by looking at the context
If isAlreadyProcessed = False Then
' More validation: check if this looks like a valid boolean attribute
' Common boolean attributes in HTML
Dim commonBooleanAttrs As List = Array As String("disabled", "readonly", "checked", "required", "selected", "multiple", "autofocus", "novalidate", "formnovalidate", "hidden")
If commonBooleanAttrs.IndexOf(attrName) > -1 Then
Parent.Attributes.Add(CreateHtmlAttribute(attrName, attrName))
Else
' Log unexpected boolean attributes for debugging
Log($"Warning: Unexpected boolean attribute: ${attrName}"$)
End If
End If
Loop
End Sub