Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple markdown formatting to rustc --explain output #112697

Merged
merged 1 commit into from
Jul 5, 2023

Commits on Jul 3, 2023

  1. Add a simple markdown parser for formatting rustc --explain

    Currently, the output of `rustc --explain foo` displays the raw markdown in a
    pager. This is acceptable, but using actual formatting makes it easier to
    understand.
    
    This patch consists of three major components:
    
    1.  A markdown parser. This is an extremely simple non-backtracking recursive
        implementation that requires normalization of the final token stream
    2.  A utility to write the token stream to an output buffer
    3.  Configuration within rustc_driver_impl to invoke this combination for
        `--explain`. Like the current implementation, it first attempts to print to
        a pager with a fallback colorized terminal, and standard print as a last
        resort.
    
        If color is disabled, or if the output does not support it, or if printing
        with color fails, it will write the raw markdown (which matches current
        behavior).
    
        Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
        and `delta`.
    
    The markdown parser does not support the entire markdown specification, but
    should support the following with reasonable accuracy:
    
    -   Headings, including formatting
    -   Comments
    -   Code, inline and fenced block (no indented block)
    -   Strong, emphasis, and strikethrough formatted text
    -   Links, anchor, inline, and reference-style
    -   Horizontal rules
    -   Unordered and ordered list items, including formatting
    
    This parser and writer should be reusable by other systems if ever needed.
    tgross35 committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    6a1c10b View commit details
    Browse the repository at this point in the history