The output of rustc --explain
is in markdown and wraps code blocks in backticks:
```
\\ example rust code
```
Is it possible to annotate the language of the code block as rust?
```rust
\\ example rust code
```
The reason is to make it possible to pipe the output to a markdown renderer such as glow which has language-specific syntax highlighting, e.g., rustc --explain Exxxx | glow
.
1 Like
eljamm
June 16, 2024, 6:07am
2
This works for me:
$ rustc --explain Exxxx | sed '/^```/{s//&rust/;:a;n;//!ba}' | glow
from:
perl, awk, sed, markdown
2 Likes
And it looks like there's not a built-in way. If I'm reading that right. (It strips any annotations from the markdown, which they do have (albeit not rust
). )
1 Like
Well, making this unconditionally add rust
would be dead simple.
text.push_str(&line[..(indent_level + 3)]);
if is_in_code_block {
text.push_str("rust");
}
Not sure if this stuff is intended to be stable. It would probably be more useful to add this to glow instead.
Sure. (But I don't think that's what the OP meant.)
Using glow was just an example. I'm viewing the output of rustc --explain
using a plugin inside neovim and want the markdown syntax to apply there as well. See spaces added to popup message breaks markdown formatting · Issue #2 · yining/vim-rustcexplain · GitHub .
1 Like
Thanks. It would be nicer if it was built in, but I've used this as a workaround.
1 Like
system
Closed
September 16, 2024, 8:41am
8
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.