html_analyzer
¶
Full name: tenets.core.analysis.implementations.html_analyzer
html_analyzer¶
HTML code analyzer with modern web framework support.
This module provides comprehensive analysis for HTML files, including support for HTML5, accessibility features, web components, and modern framework patterns.
Classes¶
HTMLStructureParser¶
Bases: HTMLParser
Custom HTML parser to extract structure information.
Source code in tenets/core/analysis/implementations/html_analyzer.py
Functions¶
handle_starttag¶
Handle opening tags.
Source code in tenets/core/analysis/implementations/html_analyzer.py
def handle_starttag(self, tag, attrs):
"""Handle opening tags."""
self.current_depth += 1
self.max_depth = max(self.max_depth, self.current_depth)
self.element_stack.append(tag)
attr_dict = dict(attrs)
element_info = {
"tag": tag,
"attrs": attr_dict,
"depth": self.current_depth,
"line": self.getpos()[0],
}
self.elements.append(element_info)
# Track specific elements
if tag == "script":
self.scripts.append(attr_dict)
elif tag == "style":
self.styles.append(attr_dict)
elif tag == "link":
self.links.append(attr_dict)
elif tag == "meta":
self.meta_tags.append(attr_dict)
elif tag == "form":
self.current_form = {
"attrs": attr_dict,
"inputs": [],
"line": self.getpos()[0],
}
self.forms.append(self.current_form)
elif tag in ["input", "textarea", "select", "button"] and self.current_form:
self.current_form["inputs"].append(
{
"tag": tag,
"attrs": attr_dict,
}
)
handle_endtag¶
handle_data¶
HTMLAnalyzer¶
Bases: LanguageAnalyzer
HTML code analyzer with modern web framework support.
Provides comprehensive analysis for HTML files including: - HTML5 semantic elements - CSS and JavaScript imports - Meta tags and SEO elements - Forms and input validation - Accessibility features (ARIA, alt text, etc.) - Web components and custom elements - Framework-specific patterns (React, Vue, Angular) - Microdata and structured data - DOM complexity and nesting depth - Performance hints (lazy loading, async/defer scripts) - Security considerations (CSP, integrity checks)
Supports HTML5 and modern web development practices.
Initialize the HTML analyzer with logger.