Wrong Coloring

Oleg's Avatar

Oleg

24 May, 2012 01:50 PM

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
  1. Support Staff 1 Posted by Brett on 24 May, 2012 01:57 PM

    Brett's Avatar

    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. 2 Posted by Oleg on 24 May, 2012 02:00 PM

    Oleg's Avatar

    I expect:

    • email address should be colored in a SAME color, not like it is colored now. See attachment .
    • this string: ~/.ssh/github_rsa should be also colored in a SAME color, not like it is now: ~ is is black /.ssh/github is blue _rsa is black
  3. Support Staff 3 Posted by Brett on 24 May, 2012 02:03 PM

    Brett's Avatar

    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. 4 Posted by Oleg on 24 May, 2012 02:18 PM

    Oleg's Avatar

    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

  5. Support Staff 5 Posted by Brett on 24 May, 2012 02:27 PM

    Brett's Avatar

    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. 6 Posted by Oleg on 24 May, 2012 02:32 PM

    Oleg's Avatar

    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.

  7. Support Staff 7 Posted by Brett on 24 May, 2012 02:45 PM

    Brett's Avatar

    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. 8 Posted by Oleg on 24 May, 2012 02:47 PM

    Oleg's Avatar

    Thanks, Brett

  9. 9 Posted by swehba on 09 Mar, 2013 11:45 PM

    swehba's Avatar

    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.

  10. Support Staff 10 Posted by Brett on 10 Mar, 2013 02:00 AM

    Brett's Avatar

    If you use fenced code blocks like this:

     ```objectivec
     all your code
     ```
    

    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. 11 Posted by swehba on 10 Mar, 2013 03:11 AM

    swehba's Avatar

    Interestingly enough, the following code is syntax colored just fine:

    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    

    Whereas this code is display all in bold and red:

    [runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
    

    Not sure why, and using explicit fences or just letting highlight.js auto-detect makes no difference.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • Screen_Shot_2012-05-24_at_09.49.26_.png 19.4 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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