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

Folding sections in code blocks #2215

Open
brendanzab opened this issue Jan 15, 2020 · 7 comments
Open

Folding sections in code blocks #2215

brendanzab opened this issue Jan 15, 2020 · 7 comments
Labels
difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. domain: theme Related to the default theme components feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@brendanzab
Copy link

brendanzab commented Jan 15, 2020

🚀 Feature

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

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

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

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

println!("hello!");

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

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:

  • 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
@brendanzab brendanzab added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Jan 15, 2020
@brendanzab
Copy link
Author

I tried posting this on Canny, but I ran into an error:

Screenshot Screen Shot 2020-01-15 at 2 03 47 pm

@elviswolcott
Copy link
Contributor

elviswolcott commented Jan 18, 2020

I have built something like this before in Docusaurus v1, I can take a tool at it if it's something the maintainers think is worth having as a core feature.

@lex111
Copy link
Contributor

lex111 commented Jan 20, 2020

I do not think that this feature should be included in core of D2. After all, you can create a plugin and enable it on demand, right?

@yangshun yangshun added difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. help wanted Asking for outside help and/or contributions to this particular issue or PR. mlh Major League Hacking Fellowship and removed status: needs triage This issue has not been triaged by maintainers labels Jun 5, 2020
@yangshun
Copy link
Contributor

yangshun commented Jun 5, 2020

It could be a fun thing to work on, but lower priority. The main reason why Kotlin docs needed it was because they allowed running code in the browser, and hence they needed to include a bunch of boilerplate runner code which was not relevant to the sample.

@brendanzab
Copy link
Author

Yeah no worries!

It can also be helpful if you're running your docs through CI, and want to have the setup code there to ensure all examples are runnable.

@Josh-Cena
Copy link
Collaborator

Time to revive this FR since we need it on our own website: a lot of the examples can be much more concise (e.g. https://docusaurus.io/docs/sidebar#collapsible-categories) if we have the other boilerplate/context collapsed

@Josh-Cena Josh-Cena added domain: theme Related to the default theme components and removed help wanted Asking for outside help and/or contributions to this particular issue or PR. mlh Major League Hacking Fellowship labels Mar 29, 2022
@Josh-Cena
Copy link
Collaborator

This will be closed without getting implemented in core. See #5783 (comment)

In the near future, I will send a PR to dogfood this on our own website, which can be used as an inspiration. I'll keep this open for now until I make that demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. domain: theme Related to the default theme components feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants