facebook / facebook/docusaurus

Allow codeblocks to show only part of the content

Đang mở
#10,026 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
proposal
Ngôn ngữ chính
TypeScript
Star
66.2k
Fork
10k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
52

Mô tả

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Motivation

Often when writing code blocks you may be writing only a part of the code, for example a method in a class, even a one-liner.

In PHP this may look like the following:
```php
public function doSomething(
string $someValue,
): void {
// ...
}
```

This works great for the most part, but it also isn't valid PHP on it's own.

It would be great if it were possible to add some metadata/comment so that you could provide the bare minimum to make the code valid, but only show the same code still.

For example:
```
```php
// docusaurus:stopDisplay
class Example {
// docusaurus:startDisplay
public function doSomething(
string $someValue,
): void {
// ...
}
// docusaurus:stopDisplay
}
\```
```

The benefit I'm after with doing this is the ability to somehow extract the full code blocks, and then to lint the code and check for any errors.

### Self-service

- [X] I'd be willing to do some initial work on this proposal myself.

I'm happy to have a go at this if given guidance on how you'd want it to look. I imagine something along the same lines as the [line highlighting](https://docusaurus.io/docs/markdown-features/code-blocks#line-highlighting) support.

I'll also suggest that whatever comment is chosen should really be prefixed with something like `docusaurus:`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.