Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML multi-line strings inconsistencies #475

Closed
ItalyPaleAle opened this issue Apr 25, 2021 · 4 comments
Closed

YAML multi-line strings inconsistencies #475

ItalyPaleAle opened this issue Apr 25, 2021 · 4 comments
Labels
help wanted lexer bug Highlighting error in a lexer

Comments

@ItalyPaleAle
Copy link

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

@silverwind
Copy link
Contributor

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.

@alecthomas
Copy link
Owner

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 alecthomas added help wanted lexer bug Highlighting error in a lexer labels Sep 18, 2021
@silverwind
Copy link
Contributor

silverwind commented Sep 21, 2021

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.

guilgaly added a commit to guilgaly/chroma that referenced this issue Jan 11, 2023
When the YAML block scalar (multiline string) syntax is used with only one line of text, the single line is not matched by the current regexp. It currently only works with at least two lines.

This fixes the regexp by adding a special case for a single line after the first indentation in the block.
alecthomas pushed a commit that referenced this issue Jan 12, 2023
When the YAML block scalar (multiline string) syntax is used with only one line of text, the single line is not matched by the current regexp. It currently only works with at least two lines.

This fixes the regexp by adding a special case for a single line after the first indentation in the block.
@jmooring
Copy link
Contributor

I think this was resolved with #724. I am now unable to reproduce the problem.

imomaliev added a commit to imomaliev/blog that referenced this issue Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted lexer bug Highlighting error in a lexer
Projects
None yet
Development

No branches or pull requests

4 participants