I've got some WIP refactor moving the rustdoc syntax highlighting code to its own crate, to allow to use it for terminal highlighting as well. As a proof of concept, I used it to highlight the code in rustc --explain
(the colors scheme is a placeholder):
@GuillaumeGomez made a comment in #33240 about experimenting with this some time back, but the referenced PR was closed due to inactivity after changing strategies to do what I ended up doing.
From that PR a point was made, that I agree with, the highlighting should (at least by default) minimal.:
I think that for syntax highlighting, I'd prefer to just find keywords and highlight them in bold (something very minimal). We have to be very wary of drawing attention away. –@nikomatsakis
Note that I am not parsing markdown from the explanations, just finding code blocks and highlighting them, but a proper solution should probably use hoedown with a custom renderer.
I believe the same syntax highlighting could be used in other compiler output, specially in diagnostics (but that might need to highlight the entire document before printing out only a few lines if we want foolproof highlighting).