-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
It might be helpful to have some more tools for rendering our code samples.
-
Be able to associate a filename with a code sample in a consistent way.
In various places we use
// some-file.js
or preface the code block with a bolded file path. These don’t always work well everywhere so a way to do this that is the same across file formats would be helpful. -
Be able to highlight specific lines in a code sample.
This can be helpful to distinguish the key lines in longer samples. Line numbers might be an alternative here although that introduces the possibility for prose to get out of sync with line numbers if the code is changed.
See also: codehike (from @sarah11918)
-
Be able to easily copy/paste code samples.
It’s fairly common for people to want to copy/paste a code sample, so we might want to make this as easy as possible.
-
Maybe a way to collapse some code by default? This would allow longer more complete code samples where the full context is available but only pertinent lines are immediately shown.
-
(h/t @hippotastic) Where it makes sense, could we connect code samples to “Try it out now” links that point to Stackblitz? (Or offer inline interactivity with https://github.com/withastro/astro-playground!)
-
The beta React docs site has a cool little component for terminal sippets. We could do something similar with a remark plugin that targets code blocks tagged
sh
/shell
?
If possible it would be good to support this with minimal syntax changes. Perhaps with a remark plugin that can read extra metadata after the triple backtick?
```js src/pages/endpoint.js
export function get() {
}
```