Author Topic: YAML custom coloring  (Read 3257 times)

garion911

  • Senior Community Member
  • Posts: 203
  • Hero Points: 13
YAML custom coloring
« on: April 20, 2020, 11:28:57 PM »
Hi all.. I'm trying to add some extra color coding to YAML, and its not working as I expect (at all really).

I use YAML quite a bit with Salt. With that, it's really YAML with Jinja templating.

So I have something like this:
Code: [Select]
{# Some jinja comment #}
{% if jinja %}
something|something:
    something:
        - name: somethingelse
{% endif %}

In the Yaml Color coding, I added a new token  {#, as a comment, with a end token of #}. Both are plain text search. I don't get any color coding, its as if it completely ignores it (see screenshot).

I'm also attaching an image of my color settings.

Additionally, this is in an 'sls' file, which I added to the YAML file types. I also tried in a .yaml file, with the same result.

SlickEdit Pro 2019 (v24.0.2.0)

Licensed number of users: Single user
License file: /Library/Application Support/SlickEdit/24/slickedit.lic

Build Date: April 1, 2020
Emulation: Brief

OS: macOS
OS Version: 10.15.4
Processor Architecture: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz 64 bit (8 cores)

Memory: 99% Load, 16268MB/16384MB Virtual
Shell Information: /Applications/SlickEditPro2019.app/Contents/MacOS/secsh -i
Screen Size: 1920 x 1200, 1440 x 900

Project Type: (Other)
Language: .sls (YAML)
Encoding: UTF-8, no signature

Installation Directory: /Applications/SlickEditPro2019.app/Contents/
Configuration Directory: /Users/.../Library/Application Support/SlickEdit/24.0.2/
Migrated from: /Users/.../Library/Application Support/SlickEdit/24.0.1/



patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: YAML custom coloring
« Reply #1 on: April 21, 2020, 07:17:36 PM »
I can reproduce that.  From taking a quick look at it, I suspect any construct with a brace in it isn't going to work for custom coloring with the YAML lexer.  I'll pass it along to the developer who is the most familiar with that lexer to take a look at.  Thanks for the report.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #2 on: April 22, 2020, 05:24:07 PM »
Most languages can be color coded using the general purpose SlickEdit color coding engine. A few languages, including YAML, Markdown have a very hard wired engine which can conflict with user additions.

Adding perfect Jinja color coding will be very hard. Preprocessing can be added anywhere and the YAML color engine is totally not designed for custom user color coding additions everywhere.

My goal is to create a "YAML with Jinja" color coding profile for v25. Can't promise anything yet.

I'm pretty sure this will have to be hard wired for YAML. If we hard wire the following, would it be useful?

{# ... #} comment
{% ... %} Embedded Jinja
{{ ... }} Embedded Jinja
## ...    Line comment
# ...     Embedded Jinja

The following is quite a tricky construct to handle. Might be doable by treating the text instead as embedded "YAML" and not "YAML with Jinja".
{% raw %}
    ...
{% endraw %}



garion911

  • Senior Community Member
  • Posts: 203
  • Hero Points: 13
Re: YAML custom coloring
« Reply #3 on: April 22, 2020, 06:07:02 PM »
For my use case, it would be enough to have the Jinja comments as comments, and {{ }}, {% %} standout somehow.. Just so i can quickly differentiate between the Jinja and YAML quickly. I dont mind reading the jinja code as a single color.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #4 on: April 22, 2020, 08:39:45 PM »
I don't think it will be hard to do embedded Jinja but I haven't yet studied the syntax thoroughly. Worst case, it can show up as embedded string color.


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #5 on: April 22, 2020, 10:31:52 PM »
I've been trying some things out.

# ...  conflicts with YAML line comments. Should this just be displayed a line comment? If we do that, ## will also be displayed as a line comment without doing anything special.

The other option would be not to support #... YAML line comments and go with Jinja embedded code and also add ## as a Jinja line comment.
« Last Edit: April 22, 2020, 11:13:43 PM by Clark »

garion911

  • Senior Community Member
  • Posts: 203
  • Hero Points: 13
Re: YAML custom coloring
« Reply #6 on: April 22, 2020, 11:49:32 PM »
Well, Jinja {# #} can span multiple lines, so don't think using it as a line comment would work properly.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #7 on: April 23, 2020, 01:22:05 AM »
In YAML with Jinja, we can treat {# ...#} differently than #... 

It shouldn't be a problem that {# ... #} can span multiple lines.

Maybe what I posted was confusing.

Arguably, #... should be color coded as embedded Jinja since that's what it is as far as Jinja is concerned. Too bad YAML comments can't be supported though.

Code: [Select]
# for item in seq:
    name: value     ## this comment is ignored
# endfor

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #8 on: April 23, 2020, 01:46:03 AM »
Take a look at these samples. It's the same code. One uses the "Slate" color profile and the other uses "Default".

garion911

  • Senior Community Member
  • Posts: 203
  • Hero Points: 13
Re: YAML custom coloring
« Reply #9 on: April 24, 2020, 10:26:01 PM »
Odd how the YAML comment and Jinja comment are different. But if it works, it works. Certainly better than I have now. Thank you!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 7041
  • Hero Points: 535
Re: YAML custom coloring
« Reply #10 on: April 24, 2020, 10:58:47 PM »
Not sure I follow what you mean. Do you mean Jinja comment or Jinja Code. The Jinja comment doesn't have a different background color at the moment. The Jinja Code (not comments) has a different background color but still identifies things like keywords and other things. I think this looks better. I tried it without changing the background color and it didn't look good. There's actually a complete "Jinja" language color coding profile defined so it can be referenced as an embedded language for any other language.

For v25, I added a "Jinja Settings..." button to the color coding dialog. It lets you configure a number of Jinja settings. See attached screen shot. YAML color coding can't really handle much Jinja configuration changes. You can add the "Line statement prefix: #" and "Line comment prefix: ##". Anything else is a crap shoot. These Jinja settings are also provided for all other languages. Adding this to HTML should be very useful.