highlightCode method
Highlights code and returns ANSI-styled output.
If language is not specified or not recognized, attempts auto-detection.
Falls back to plain text styling if highlighting fails.
Implementation
String highlightCode(String code, {String? language}) {
final nodes = _parseHighlightedNodes(code, language: language);
if (nodes != null && nodes.isNotEmpty) {
return _nodesToAnsi(nodes);
}
// Default: return with text style
final textStyle = theme.text;
if (textStyle != null) {
return textStyle.inline(true).render(code);
}
return code;
}