Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow codeblocks to show only part of the content #10026

Open
2 tasks done
andrewnicols opened this issue Apr 6, 2024 · 2 comments
Open
2 tasks done

Allow codeblocks to show only part of the content #10026

andrewnicols opened this issue Apr 6, 2024 · 2 comments
Labels
proposal This issue is a proposal, usually non-trivial change

Comments

@andrewnicols
Copy link
Contributor

andrewnicols commented Apr 6, 2024

Have you read the Contributing Guidelines on 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:

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

  • 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 support.

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

@andrewnicols andrewnicols added proposal This issue is a proposal, usually non-trivial change status: needs triage This issue has not been triaged by maintainers labels Apr 6, 2024
@slorber
Copy link
Collaborator

slorber commented Apr 11, 2024

I don't understand sorry, please use JS instead of PHP because it's been a while I haven't touched it. Can you draw a mockup of the expected result output? Is there any other doc solution that has that feature we could look at?

What prevents you from building this by swizzling our theme CodeBlock? Or creating a POC in a PR?

This way we can understand the UX you want, before even considering adding it to Docusaurus core.

If things can be built in userland, I'd prefer it to be, unless the community clearly show traction for this feature (which remains to be proven once it becomes clearer). If things are not easy to build in userland, we can work to make them easier to build.

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Apr 11, 2024
@Josh-Cena
Copy link
Collaborator

I'm not sure, but would magic comments paired with display: none solve this?

This also seems highly related to #2215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue is a proposal, usually non-trivial change
Projects
None yet
Development

No branches or pull requests

3 participants