https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116792
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>: https://gcc.gnu.org/g:a746747e2102c965a7736dc22ba56c3bc8e3e61e commit r16-1024-ga746747e2102c965a7736dc22ba56c3bc8e3e61e Author: David Malcolm <dmalc...@redhat.com> Date: Fri May 30 19:57:46 2025 -0400 diagnostics: implement highlight-a vs -b in HTML output [PR116792] Update HTML output so that it renders highlight-a vs highlight-b via <span> tags in the message itself, in the quoted source line, in the underlines, and in the labels and their vertical bars. Example output can be seen at: https://dmalcolm.fedorapeople.org/gcc/2025-05-28/diagnostic-ranges.c.html gcc/ChangeLog: PR other/116792 * diagnostic-format-html.cc (HTML_STYLE): Add ".highlight-a" and ".highlight-b". (html_builder::make_element_for_diagnostic): Handle begin_color and end_color. * diagnostic-show-locus.cc (to_html::to_html): Add "richloc" param and use it to initialize m_richloc. (to_html::colorize_text_for_range_idx): Drop. (to_html::get_location_range_by_idx): New. (to_html::get_highlight_color_for_range_idx): New. (to_html::m_richloc): New field. (print_html_span_start): Update for new param of to_html ctor. (line_printer::m_was_in_range_p): New field. (line_printer::m_last_range_idx): New field. (layout_printer<Sink>::print_source_line): Use set_in_range and set_outside_range rather than colorization calls. (layout_printer<Sink>::set_in_range): New. (layout_printer<Sink>::set_outside_range): New. (layout_printer<Sink>::print_annotation_line): Use set_in_range and set_outside_range rather than colorization calls. (layout_printer<to_text>::begin_label): Convert param from label to state_idx. Add "is_label_text" param and use it to guard logic for turning off colorization within paths. (layout_printer<to_html>::begin_label): Likewise. Push <span> for any highlight color. (layout_printer<to_text>::end_label): Likewise. (layout_printer<to_text>::end_label): Likewise, popping the <span>. (layout_printer<Sink>::print_any_labels): Convert begin/end_label calls to pass in state_idx rather than label. Use begin/end_label rather than colorization calls. (layout_printer<Sink>::layout_printer): Likewise. (layout_printer<Sink>::layout_printer): Initialize new fields. (diagnostic_source_print_policy::print_as_html): Update for new param of to_html ctor. gcc/testsuite/ChangeLog: PR other/116792 * gcc.dg/format/diagnostic-ranges-html.py: New test script. * gcc.dg/format/diagnostic-ranges.c: Add HTML generation to options, and invoke the new script to check the HTML output. Signed-off-by: David Malcolm <dmalc...@redhat.com>