Skip to content

Improve code sample tooling #918

@delucis

Description

@delucis

It might be helpful to have some more tools for rendering our code samples.

  1. 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.

  2. 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)

  3. 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.

  4. 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.

  5. (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!)

  6. 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?
    image

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() {
}
```

Metadata

Metadata

Labels

site improvementSome thing that improves the website functionality - ask @delucis for help!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions