11

I'm dealing with one issue on GitHub and for that, the moderator is requesting me to share the output of certain bash commands in the comments. I'm sharing the output of requested commands in the form of code blocks and I know how to insert code block in Markdown:

The output of the command
.
.
.

However, the problem with the above syntax is that if the command output has let say 500 lines then it will display all the 500 lines in the Markdown output. In fact, there total of 3 such long code blocks in my comment. Because of that, code blocks consume a significant amount of space in my comment and my comment seems too long.

So, is there any way that my code block would display only a limited number of lines with a scrolling feature specific to that block only e.g. it should display only 10 lines, and for the rest of the lines, it should have vertical scrolling. Through this, my comment won't seem too long and the moderator would also be to focus on other non-command text (i.e. content other than code blocks) in my comment.

2
  • 1
    I don't think you can. Maybe post core snippets in the comment and links to Gists for the full output? That's how e.g. Terraform issues are encouraged: "Please create a GitHub Gist containing the debug output. Please do _not_ paste the debug output in the issue, since debug output is long."
    – jonrsharpe
    Jul 21, 2020 at 21:55
  • Oh, had not thought about Gists before for this. Thanks for the suggestions. In my opinion, Gists are not that much convenient for commenting but still, I think better than simple comment which consumes hundreds of line and you get tired of scrolling & scrolling.
    – Milan
    Jul 28, 2020 at 19:10

1 Answer 1

18

GitHub Flavored Markdown allows you to use html tags. So you can use details html block to hide your long code.

<details>
  <summary>
    summary
  </summary>
  details
</details>

It looks like this collapsed:

Collapsed

and expanded:

Expanded

4
  • 1
    This worked for sublime text’s markdown parser, but I’d wonder if you would be able to put a markdown code block inside a <details/> html tag in other editors.
    – owengall
    Sep 22, 2020 at 22:49
  • It is very common for editors to convert markdown to html so it should be possible in most of them. Sep 27, 2020 at 23:15
  • 2
    Excellent, but note that programming code gets formatted as ordinary text if pasted as details above. Any solutions for that last-mile problem?
    – mirekphd
    Oct 5 at 15:34
  • @mirekphd Yes you can still have it format as code, just wrap it with " ``` ``` " ex: <details> <summary>Expand Code</summary> ```tsx console.log('hello') ``` </details>
    – Hugobop
    Oct 31 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.