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:
-
Unfolded:
-
Markdown source:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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