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

Accept colon(s) in YAML key names #2277

Merged
merged 1 commit into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygments/lexers/data.py
Expand Up @@ -231,7 +231,7 @@ def callback(lexer, match, context):
# whitespaces separating tokens
(r'[ ]+', Whitespace),
# key with colon
(r'''([^#,:?\[\]{}"'\n]+)(:)(?=[ ]|$)''',
(r'''([^#,?\[\]{}"'\n]+)(:)(?=[ ]|$)''',
bygroups(Name.Tag, set_indent(Punctuation, implicit=True))),
# tags, anchors and aliases,
include('descriptors'),
Expand Down
11 changes: 11 additions & 0 deletions tests/snippets/yaml/test_yaml_colon_in_key.txt
@@ -0,0 +1,11 @@
# Colon in the key name is accepted by the YAML specs too

---input---
foo:bar: value

---tokens---
'foo:bar' Name.Tag
':' Punctuation
' ' Text.Whitespace
'value' Literal.Scalar.Plain
'\n' Text.Whitespace
11 changes: 11 additions & 0 deletions tests/snippets/yaml/test_yaml_colon_in_key_double.txt
@@ -0,0 +1,11 @@
# Colons in the key name is accepted by the YAML specs too

---input---
foo::bar: value

---tokens---
'foo::bar' Name.Tag
':' Punctuation
' ' Text.Whitespace
'value' Literal.Scalar.Plain
'\n' Text.Whitespace
11 changes: 11 additions & 0 deletions tests/snippets/yaml/test_yaml_colon_in_key_start.txt
@@ -0,0 +1,11 @@
# Colon at the beginning of the key name is accepted by the YAML specs too

---input---
:foo: value

---tokens---
':foo' Name.Tag
':' Punctuation
' ' Text.Whitespace
'value' Literal.Scalar.Plain
'\n' Text.Whitespace