primer-spec icon indicating copy to clipboard operation
primer-spec copied to clipboard

Hidden lines of code?

Open eecs441staff opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. Often times one only wants to display several lines of code. Displaying these lines without context could confuse the reader. Displaying them with surrounding lines could lead to reader cut and pasting duplicated code. Is there a way to "hide" contextual lines of code by default but reveal them, properly formatted and syntax highlighted, with the click of a button?

Describe the solution you'd like Like this: https://rust-lang.github.io/mdBook/format/theme/syntax-highlighting.html#hiding-code-lines

Describe alternatives you've considered To show the contextual lines commented out, but then it wouldn't be properly formatted and syntax highlighted and could be confusing.

Additional context Add any other context or screenshots about the feature request here.

eecs441staff avatar Jun 12 '22 16:06 eecs441staff

(Sorry for my delayed reply while I've been traveling!)

That's a really interesting feature request. I really like the example you linked to! A couple of my initial thoughts:

  • The example you linked to seems to assume that code blocks with never have full-line text comments. Or maybe they're doing some fancy parsing to ensure that the full code-block is syntactically valid? I'm not sure, I'd have to give it a try.
  • We are kind-of limited by the default syntax-highlighter included with Jekyll. I think we'd need to switch to an in-browser syntax-highlighter to unlock features like this.

I'll give this further thought in the coming weeks.

seshrs avatar Jul 03 '22 13:07 seshrs

Oh this could be as easy as adding a data-hidden-lines attribute 😅

My next question: How does this affect line numbers? Maybe this feature should only be allowed with the no-line-numbers variant? I'll need to give this further thought.

seshrs avatar Aug 01 '22 03:08 seshrs