Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

Better Syntax highlighting

Open joshkel opened this issue 10 years ago • 30 comments

Syntax highlighting for ``` code blocks would be nifty.

My personal preference would be for something like GitHub Flavored Markdown's syntax highlighting, simply because that's what I'm most familiar with, but I don't have a strong opinion on this.

joshkel avatar Dec 07 '15 20:12 joshkel

So turns out this is kind of here. We just need to improve the css for this so its a little more obvious.

geekgonecrazy avatar Dec 07 '15 20:12 geekgonecrazy

I don't understand.. we already have the feature.. so what is the request here?

engelgabriel avatar Dec 08 '15 15:12 engelgabriel

image

engelgabriel avatar Dec 08 '15 15:12 engelgabriel

From playing around with this, there are several shortcomings. For example:

I don't see the ``` syntax documented anywhere in the current software. (The only information I can find on formatting in general is a bullet point mention of "Markdown" under features and a very brief list of some syntax in the lower right corner of chat.)

I can't find any list of supported languages.

The syntax highlighting isn't very good. For example:

  • In your example, require should be highlighted as a keyword.
  • array shows up as a built-in in C++ code. (It isn't.)
  • The attached screenshot shows the same code highlighted differently C and C++, but C and C++ should be highlighted the same in this case. (The C version is mostly correct - printf shouldn't be highlighted as a built-in, IMO, and highlighting %i within the string is correct - although neither version correctly gives keywords for and int a different appearance than the variable name i). 2015-12-09 11_25_26-rocket chat

None of this is a high priority for us right now, but if you'd like me to open any of these as separate issues, please let me know.

joshkel avatar Dec 09 '15 16:12 joshkel

Did you specify the language after the ```?

We currently use https://github.com/stubailo/meteor-highlight.js/tree/master

But we can add support to https://github.com/codemirror/codemirror if you think it is more powerful?

engelgabriel avatar Dec 09 '15 16:12 engelgabriel

I think we need an option to not highlight the code, currently it always highlights which is not always the right thing. for example it highlights command line instructions incorrectly: rocket

my work around is to label it as java (and that works most of the time, might not always be true)

rocket1

also as you see it is not working correctly under Firefox, as the backtick is causing some problem. While in chrome it works fine (same output on chrome) rocket2

fduraibi avatar Jan 15 '16 17:01 fduraibi

Seems like maybe we should look at codemirror. Or something with a bit better syntax highlighting

geekgonecrazy avatar Jan 15 '16 17:01 geekgonecrazy

+1

vetash avatar Jan 15 '16 18:01 vetash

Yes add this please +1

Deadlyhacker avatar Mar 23 '16 00:03 Deadlyhacker

+1, I'd love to see this get improved. Being a C++ developer, I second everything that @joshkel said about the C / C++ syntax highlighting.

jseadragon avatar Apr 25 '16 15:04 jseadragon

@rodrigok now that we have codemirror, should we use it for the Syntax highlighting?

engelgabriel avatar Apr 25 '16 15:04 engelgabriel

I try to highlight scala code, but it seems not supported using ```scala :/ Any news here ?

reyman avatar Jul 13 '16 12:07 reyman

@engelgabriel Do you have an up-to-date documentation about the code highlighting topic with a list of supported languages and explanation on how to use this? It seems this site is outdated: https://sourceforge.net/p/rocketchat/wiki/markdown_syntax/

Franziskus1988 avatar Sep 06 '16 10:09 Franziskus1988

@Franziskus1988 i'm not sure where that particular documentation came from. But our official documentation can be found here: https://rocket.chat/docs And nothing more detailed then that currently, sorry.

geekgonecrazy avatar Sep 09 '16 01:09 geekgonecrazy

The main problem with using meteor highlight js is: the integrated highlight js is 2 years old (Oct 28, 2014) Not plan to upgrade the highlight js (in a forked repository) or using highlight.js directly in the application?

b0c1 avatar Feb 08 '17 09:02 b0c1

This is solved in https://github.com/RocketChat/Rocket.Chat/commit/ffc0bdaed34af88bddc16d7eedb2cfeb635cd0d3, right?

Rohlik avatar Mar 24 '17 11:03 Rohlik

@Rohlik - From testing the Docker image of 0.54.0, most of the problems I listed here are still an issue:

  1. Whatever theme or stylesheet is being applied fails to give keywords their own color.
  2. I can't find any official list of supported languages. (This and this seem to work.)
  3. array shows up as a built-in in C++ code. (It isn't.)
  4. The issue I mentioned about C versus C++ no longer exists, because Highlight.js doesn't support C as a separate language. (That's surprising, but I can live with it.)

3 and 4 are issues in Highlight.js itself, but I believe 1 and 2 are within Rocket.chat and its docs.

joshkel avatar Mar 27 '17 13:03 joshkel

I just want to be able to have "text" highlighting, In any other highlighter this would be synonymous with "Disable highlighting, but still have preformatted text blocks".

Generally I would expect

:::text
:::txt
```text
```txt 

But those don't do anything. Note how on github, it doesn't get confused by the use of triple backticks inside triple backticks, either.

xenithorb avatar Jul 14 '17 15:07 xenithorb

Lack of message formatting documentation is referenced in RocketChat/docs#971

dannysauer avatar Jan 22 '19 19:01 dannysauer

Did you specify the language after the ```?

We currently use https://github.com/stubailo/meteor-highlight.js/tree/master

But we can add support to https://github.com/codemirror/codemirror if you think it is more powerful?

How to specify the language after the ```?

brahmaparush avatar Feb 07 '19 10:02 brahmaparush