Skip to content

syntax: yaml: only treat word: as a key when followed by whitespace - #4293

Open
thelastbackspace wants to merge 1 commit into
micro-editor:masterfrom
thelastbackspace:fix/4286-yaml-colon-highlight
Open

thelastbackspace wants to merge 1 commit into
micro-editor:masterfrom
thelastbackspace:fix/4286-yaml-colon-highlight

Conversation

@thelastbackspace

Copy link
Copy Markdown

Fixes #4286

The YAML rules highlighted any word: as a key and every : as a mapping colon, so plain scalars like - http:example.com or url: http://x.com:80/a got key colouring halfway through the value. In YAML a colon only starts a value when it's followed by whitespace or the end of the line, so both rules now require that.

The second thing in the screenshot: - 'http:example.com' left the - uncoloured. The quoted string region starts with (^| )', so it takes the space after the dash, and the sequence rule ^[[:space:]]*- no longer matched. It now accepts - followed by a space or the end of the text before the region.

I checked it by dumping the highlight groups for a few lines before and after with a throwaway program on top of pkg/highlight:

before
"- http:example.com"      [statement]- [type]http[statement]:[]example.com
"- 'http:example.com'"    []-[constant.string] '...
"url: http://x.com:80/a"  [type]url[statement]: [type]http[statement]:[]//[type]x.com[statement]:[]80/a
after
"- http:example.com"      [statement]- []http:example.com
"- 'http:example.com'"    [statement]-[constant.string] '...
"url: http://x.com:80/a"  [type]url[statement]: []http://x.com:80/a

key: value, key: at end of line, key: |, key: >, tab after the colon, -x: 1 and - -x come out the same as before.

A colon only starts a mapping value when it is followed by whitespace or
the end of the line, so `- http:example.com` and `url: http://x.com:80`
are plain scalars. Also highlight the `-` of a sequence item whose value
is a quoted string; the string region ate the space the rule needed.

Fixes micro-editor#4286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid highlighting of YAML strings containing colons

1 participant