chroma icon indicating copy to clipboard operation
chroma copied to clipboard

YAML multi-line strings inconsistencies

Open ItalyPaleAle opened this issue 4 years ago • 3 comments
trafficstars

In recent updates to Chroma, yaml multi-line strings (starting with |) seem to be rendered inconsistently.

Example:

steps:

  # Sets FOO to be "some value" in the script and the next ones
  - bash: |
      FOO="some value"
      echo "##vso[task.setvariable variable=FOO]$FOO"

  # Using the $() syntax, the value is replaced inside Azure Pipelines before being submitted to the script task
  - bash: |
      echo "$(FOO)"

  # The same variable is also present as environmental variable in scripts; here the variable expansion happens within bash
  - bash: |
      echo "$FOO"

This renders as:

image

As you can see, if there's a single line in the multiline string, the number of spaces at the beginning is increased (to match the | character's position). The color is also different. Adding more than one line with the same indentation (even if empty), fixes that.

While the resulting, rendered YAML is valid, it looks odd

ItalyPaleAle avatar Apr 25 '21 21:04 ItalyPaleAle

It seems that whitespace is rendered twice. Simple repro:

key: |
  value

HTML of second line:

<span style="color:#d88200">  </span>  <span style="color:#ae81ff">value</span>

The 2 spaces are rendered highlighted once inside the first <span> and then again unhighlighted following that span.

silverwind avatar Aug 10 '21 12:08 silverwind

Unfortunately YAML is horrifically difficult to parse, and Chroma's lexer is consequently not that robust. You can see the complexity in the Pygments lexer.

alecthomas avatar Sep 18 '21 08:09 alecthomas

I think it would be a good test case to verify whether the textContent of the HTML output matches the input code exactly. With such a test, bugs like double whitespace rendering should not be possible anymore.

silverwind avatar Sep 21 '21 11:09 silverwind

I think this was resolved with https://github.com/alecthomas/chroma/pull/724. I am now unable to reproduce the problem.

jmooring avatar Feb 28 '23 23:02 jmooring