question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Folding sections in code blocks

See original GitHub issue

🚀 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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Josh-Cenacommented, Oct 25, 2021

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

0reactions
Josh-Cenacommented, May 4, 2022

This will be closed without getting implemented in core. See https://github.com/facebook/docusaurus/pull/5783#issuecomment-1117161022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collapsible Code Blocks
the code compiles fine but yu can collapse those regions easily. For this purpose make sure you have enabled Settings->Editor->"Folding"->"Fold ...
Read more >
Code Folding | IntelliJ IDEA Documentation - JetBrains
Custom folding regions - blocks of code within matched pairs of curly braces {} , learn more from Expand or collapse code elements....
Read more >
Folding Blocks of Code in C and C++ Files
In the Quote_1 application project, open the Source Files folder, then double-click the cpu.cc file to open it in the Source Editor. ·...
Read more >
How to: Collapse and Hide Sections of Code - Visual Basic
In this article​​ The #Region directive enables you to collapse and hide sections of code in Visual Basic files. The #Region directive lets...
Read more >
Code Folding and Sections in the RStudio IDE - Posit Support
You can also fold an arbitrary selection of code by using Edit -> Folding -> Collapse (Alt-L). Folded regions are preserved while editing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found