facebook / facebook/docusaurus

Folding sections in code blocks

未关闭
#2,215 7 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
difficulty: intermediate domain: theme feature
主要语言
TypeScript
星标
66.2k
派生
10k
平均合并
1 天 3 小时
30 天内合并 PR
52

描述

## 🚀 Feature

Allow irrelevant sections of code to be folded away in code samples.

## Have you read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/master/CONTRIBUTING.md#reporting-new-issues)?

Yes

## Motivation

Sometimes it's nice to be able to fold away irrelevant sections in a full code example, so that you can focus on the important parts.

## Pitch

For example, if I wrote a Rust function:

```rust
fn main() {
// sample:start
println!("hello!");
// sample:end
}
```

I'd want it to display as (note the indentation):

```rust
println!("hello!");
```

There would be a button on the code block to allow this to be expanded to the full code:

```rust
fn main() {
println!("hello!");
}
```

### Example: Kotlin's documentation

For a live example, you can check out the Kotlin docs. They seem to have a nice UI for unfolding examples. For example, [here is their documentation on defining variables](https://kotlinlang.org/docs/reference/basic-syntax.html#defining-variables):

- Folded:

Screen Shot 2020-01-15 at 1 52 20 pm
- Unfolded:

Screen Shot 2020-01-15 at 1 52 28 pm
- Markdown source:

Screen Shot 2020-01-15 at 1 47 32 pm

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。