diff --git a/plugin/core/views.py b/plugin/core/views.py index 115d70ceb..2f2bec8ca 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -980,39 +980,33 @@ def _format_diagnostic_related_info( ) -def _with_color(text: str, hexcolor: str) -> str: - return '{}'.format(hexcolor, text2html(text)) +def _html_element(name: str, text: str, class_name: Optional[str] = None, escape: bool = True) -> str: + return '<{0}{2}>{1}{0}>'.format( + name, + text2html(text) if escape else text, + ' class="{}"'.format(text2html(class_name)) if class_name else '' + ) def format_diagnostic_for_html(config: ClientConfig, diagnostic: Diagnostic, base_dir: Optional[str] = None) -> str: - formatted = [ - '
', - text2html(diagnostic["message"]) - ] + html = _html_element('span', diagnostic["message"]) code = diagnostic.get("code") source = diagnostic.get("source") if source or code is not None: - formatted.append(" ") - if source: - formatted.append(_with_color(source, "color(var(--foreground) alpha(0.6))")) - if code is not None: - formatted.append(_with_color("(", "color(var(--foreground) alpha(0.6))")) - code_description = diagnostic.get("codeDescription") - if code_description: - formatted.append(make_link(code_description["href"], str(code))) - else: - formatted.append(_with_color(str(code), "color(var(--foreground) alpha(0.6))")) - formatted.append(_with_color(")", "color(var(--foreground) alpha(0.6))")) + meta_info = "" + if source: + meta_info += text2html(source) + if code is not None: + code_description = diagnostic.get("codeDescription") + meta_info += "({})".format( + make_link(code_description["href"], str(code)) if code_description else text2html(str(code))) + html += " " + _html_element("span", meta_info, class_name="color-muted", escape=False) related_infos = diagnostic.get("relatedInformation") if related_infos: - formatted.append('") - return "".join(formatted) + info = "') - formatted.append("") - formatted.append("
".join(_format_diagnostic_related_info(config, info, base_dir) - for info in related_infos)) - formatted.append("