code-hike / codehike

Marvellous code walkthroughs
https://codehike.org
MIT License
4.39k stars 135 forks source link

Add annotation to collapse lines #259

Open zentol opened 1 year ago

zentol commented 1 year ago

When embedding somewhat larger pieces of code it can happen that the focused code is spread around quite a bit. Currently everything between focused lines is being rendered, which causes code blocks to be larger than necessary.

It would be nice to have an annotation to hide certain lines, similar to how focus works.

pomber commented 1 year ago

Can you provide an example of your problem (a screenshot is ok)?

You want to collapse lines that are between other focused lines, right?

zentol commented 1 year ago

In this example I'd like to hide the getEvent()/getMetaData() methods, but not out.collect(new EnrichedEvent(event, metadata, headers)); (below the first focused line).

I think collapsing all unfocused lines wouldn't be desirable; you'd lose some context unless you expand the focus. In the example above, the contents of of deserialize method are important for context, although we focus on a particular line. Meanwhile, the 2 methods aren't relevant anymore, because they are covered elsewhere.

pomber commented 1 year ago

Ok, so you want something like:

```python hello.py focus=6,24:35 collapse=10:22
# ...
zentol commented 1 year ago

yes, that would work.