markup icon indicating copy to clipboard operation
markup copied to clipboard

Support ANSI coloring in code blocks

Open ramonsmits opened this issue 1 year ago • 7 comments

It would be great if the following code block would support ANSI coloring:

[30m	Black Text
[31m	Red Text
[32m	Green Text
[33m	Yellow Text
[34m	Blue Text
[35m	Purple Text
[36m	Cyan Text
[37m	White Text

I tried txt, cmd, bash, shell but none seem to support this (yet..). This would be awesome for sharing log snippets and other console output.

I explicitly only want it in code blocks and not in regular markdown as I don't think it coloring must not be part of the formatting.

Maybe via for example the syntax keyword ansi if it should not be applied to all but I guess it makes sense to apply to all shell related formatters.

Related:

  • bot closed https://github.com/github/markup/issues/1538

ramonsmits avatar Dec 10 '24 12:12 ramonsmits

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Feb 09 '25 12:02 github-actions[bot]

So, people are showing positive emojis but no response/triage from GitHub. Any chance this will be added? I understand not all ansi commands can be supported but coloring should be pretty easy.

ramonsmits avatar Feb 09 '25 23:02 ramonsmits

Is maybe https://github.com/github-linguist/linguist a better repo?

ramonsmits avatar Feb 09 '25 23:02 ramonsmits

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 11 '25 12:04 github-actions[bot]

Would absolutely love to see this! Unfortunately, I suspect it might need to be implemented somewhere else, based on the README:

This library is the first step of a journey that every markup file in a repository goes on before it is rendered on GitHub.com:

  1. github-markup selects an underlying library to convert the raw markup to HTML. See the list of supported markup formats below.
  2. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes.
  3. Syntax highlighting is performed on code blocks. See github/linguist for more information about syntax highlighting.
  4. The HTML is passed through other filters that add special sauce, such as emoji, task lists, named anchors, CDN caching for images, and autolinking.
  5. The resulting HTML is rendered on GitHub.com.

Please note that only the first step is covered by this gem — the rest happens on GitHub.com.

In other words, if markup were to automatically convert \e[32mERROR\e[0m to something like <span class="ansi-red">ERROR</span>, it wouldn't matter because:

  • The sanitization step would remove the class attribute
  • GitHub's CSS would need to be updated to include appropriate ANSI color/etc. classes. The current syntax highlighting classes are not appropriate for this, since they are not organized around colors, but rather the semantic meaning of a particular token (e.g. pl-s is used for string literals, and happens to be blue).

So it sounds like this would need to be implemented somewhere in the vicinity of steps 3-5 (but also not within linguist since it doesn't actually output HTML 😞)

Edit Though I suppose this could be implemented in markup if 1. GitHub explicitly added CSS classes for ANSI colors and 2. explicitly whitelisted their usage in its sanitization logic. That would also generally solve this issue, since people could then use those classes outside of code blocks 🥳

jenseng avatar Apr 17 '25 22:04 jenseng

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 17 '25 12:06 github-actions[bot]

not solved

simonvonhackewitz avatar Jun 23 '25 09:06 simonvonhackewitz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 23 '25 12:08 github-actions[bot]