Skip to content

Minor YAML highlighting issue #177

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

Closed
javiereguiluz opened this issue Jul 29, 2024 · 1 comment · Fixed by #179
Closed

Minor YAML highlighting issue #177

javiereguiluz opened this issue Jul 29, 2024 · 1 comment · Fixed by #179

Comments

@javiereguiluz
Copy link
Collaborator

First reported here: symfony/symfony-docs#20078

When using underscores to make config more readable, some numeric values are wrongly (and partially) highlighted as strings instead of numbers:

image

@homersimpsons
Copy link
Contributor

homersimpsons commented Aug 1, 2024

I did some digging.

It looks like what is happening is:

  1. A yaml code block is identified and processed https://github.com/symfony-tools/docs-builder/blob/main/src/Directive/CodeBlockDirective.php
  2. This class is then responsible for highltighting https://github.com/symfony-tools/docs-builder/blob/main/src/Renderers/CodeNodeRenderer.php
  3. For yaml it internally uses this project https://github.com/scrivo/highlight.php

Possible fixes:

  1. Override yaml highlighting: https://github.com/symfony-tools/docs-builder/blob/main/src/Templates/highlight.php/README.md, most probably this line: https://github.com/scrivo/highlight.php/blob/d1c6b0956a2b0d3efc137e4d8c5bf5c5e220bac1/src/Highlight/languages/yaml.json#L84
  2. Use another (maintained) library such as https://github.com/tempestphp/highlight, it does not seem to correctly highlight yaml numbers though https://github.com/tempestphp/highlight/tree/main/src/Languages/Yaml/Patterns

I think the first option should be the most straightforward and the less risky. The second option may be better in the long term.

On the symfony part, it looks like https://github.com/symfony/yaml/blob/fa34c77015aa6720469db7003567b9f772492bf2/Inline.php#L695-L738 is responsible to convert numbers. From my understanding we can have _ anywhere: _32 will be considered as a number (TODO: test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants