Hi all, I have been very excited about the ability to use README's as module documentation ever since Rust 1.54 landed and #![doc = include_str!("README.md")]
became available. However when I started trying to actually use this pattern, I ran into some problems. Basically, I would like all of the following to work:
- To have code samples that get compiled and run by Rustdoc (in the README)
- To have syntax highlighting work as expected when rendering as plain markdown (e.g. github-flavored markdown).
- This should include code that is marked
no_run
orignore
- This should include code that is marked
As of now, these goals are at odds with one another. For example, none of the following types of code fences will give me the results I want:
```
```no_run
```ignore
Each of these is interpreted by rustdoc to mean "Rust code here" and to either
- Compile and run
- Compile only
- Syntax highlight only
respectively, however on other markdown renderers these will not be interpreted to mean Rust code is inside.
I am wondering whether it'd be possible to add aliases to each of these code fences so that these all work:
- Compile and run Rust
```
```rustdoc
- Compile and syntax-highlight as Rust
```no_run
```rustdoc_no_run
- Syntax highlight as Rust, applying rustdoc formatting rules (e.g. hiding lines beginning with
#
)
```ignore
```rustdoc_ignore
- Treat as non-rust text
```text
```rustdoc_text
The objective with these is that while writing module documentation in README files, one can use the rustdoc_*
style code-fence info-strings, and we can hopefully push for popular markdown parser/renderers to treat these the same way that rustdoc does. This would allow folks to write code snippets in READMEs that get compiled and tested just like any other rustdoc test, which I think would be awesome.
What does everybody think about this? I'm interested in hearing opinions, whether this should or shouldn't be done, should be done differently, or whether there are any tips on a path forward with integrating with the greater markdown ecosystem.