Wrong Coloring
Hello:
The following text previed in Marked is colored wrong:
To Create a new SSH Keys
ssh-keygen -t rsa -C "[email blocked]"
SSH config file
Host github.com
User user
IdentityFile ~/.ssh/github_rsa
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 24 May, 2012 01:57 PM
The syntax coloring is a best-guess pick based on regex matches in the string. You can specify a language for recognition, but on short code snippets (especially config files for which there are no language definitions) you're probably not going to get any predictable results.
What coloring are you expecting? If it's Pygments coloring, you can always paste pygemtized code in instead of a code block or set up a custom processor to use pygments instead of the default highlight.js.
2 Posted by Oleg on 24 May, 2012 02:00 PM
I expect:
Support Staff 3 Posted by Brett on 24 May, 2012 02:03 PM
No, I get that. What I'm asking is in what system is that working correctly for you? The built-in highlighting is probably never going to get a short snippet like that right, but if you know a system that does, we can try to work that into Marked instead.
4 Posted by Oleg on 24 May, 2012 02:18 PM
I do not understand what do you mean by asking in "in what system" ?
I thought doing regex to find email and coloring it using the same color is not a big deal. Moreover you already doing it with green in my example and than changing @mac to magenta ??? Also if I change quotes "" to '' email address is not colored at all. I understand that in some programming languages @ means something, but in my example string is in quotes, so it means it is a STRING not a code predicate.
The same applicable to a file name. I think regex can distinguish a file name and color it the same.
May be I'm missing a point.
Oleg
Support Staff 5 Posted by Brett on 24 May, 2012 02:27 PM
You are missing the point. The highlighting parser in Marked is a javascript library (highlight.js). I didn't write it, I include it. It is not capable of doing the highlighting you want on these short snippets and I'm not going to modify it. If you know of a highlighting parser (such as Pygments) that can do it correctly, I can help you use it for highlighting in Marked instead.
6 Posted by Oleg on 24 May, 2012 02:32 PM
I see. I will educate myself about Pygments (never heard about it before).
Is it possible to turn on/off highlight.js on a per file basis ? So all "problematic" files will be excluded from coloring. I think currently this is a global setting.
Support Staff 7 Posted by Brett on 24 May, 2012 02:45 PM
It is a global setting. I may introduce a means of triggering it per-file in the future. There are currently no persistent document settings, so it's a bit futile right now to handle per-file preferences. There will be soon, though.
8 Posted by Oleg on 24 May, 2012 02:47 PM
Thanks, Brett
9 Posted by swehba on 09 Mar, 2013 11:45 PM
Brett, Is the global setting something we can configure? If so, how do we do that, and what syntax do we use? If, for instance, I want to make that highlight.js uses formatting for Objective-C, how to I set that within Marked? Thanks, Steve.
P.S. I ask this because I find highlight.js frequently miscolors Objective-C code.
Support Staff 10 Posted by Brett on 10 Mar, 2013 02:00 AM
If you use fenced code blocks like this:
It will add the class that highlight.js uses. It should autodetect the language, but it depends on the code. Unfortunately the current version of Marked can only handle a few fenced code blocks before it slows down. This is fixed (and highlight.js is updated) for the next release.
You can see the available languages here.
11 Posted by swehba on 10 Mar, 2013 03:11 AM
Interestingly enough, the following code is syntax colored just fine:
Whereas this code is display all in bold and red:
Not sure why, and using explicit fences or just letting highlight.js auto-detect makes no difference.