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

fix highlighting of YAMLs anchor & alias #2217

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions components/prism-yaml.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Prism.languages.yaml = {
'scalar': {
pattern: /([\-:]\s*(?:![^\s]+)?[ \t]*[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/,
pattern: /([\-:]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/,
lookbehind: true,
alias: 'string'
},
Expand All @@ -16,32 +16,32 @@ Prism.languages.yaml = {
alias: 'important'
},
'datetime': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?)(?=[ \t]*(?:$|,|]|}))/m,
pattern: /([:\-,[{]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*)(?:\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?)(?=[ \t]*(?:$|,|]|}))/m,
lookbehind: true,
alias: 'number'
},
'boolean': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:true|false)[ \t]*(?=$|,|]|})/im,
pattern: /([:\-,[{]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*)(?:true|false)[ \t]*(?=$|,|]|})/im,
lookbehind: true,
alias: 'important'
},
'null': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:null|~)[ \t]*(?=$|,|]|})/im,
pattern: /([:\-,[{]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*)(?:null|~)[ \t]*(?=$|,|]|})/im,
toaster marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
alias: 'important'
},
'string': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|\s*#))/m,
pattern: /([:\-,[{]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|\s*#))/m,
lookbehind: true,
greedy: true
},
'number': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)[ \t]*(?=$|,|]|})/im,
pattern: /([:\-,[{]\s*(?:![^\s]+)?(?:[&*][^\s\[\]{},]+)?[ \t]*)[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)[ \t]*(?=$|,|]|})/im,
lookbehind: true
},
'tag': /![^\s]+/,
'important': /[&*][\w]+/,
'important': /[&*][^\s\[\]{},]+/,
'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
};

Prism.languages.yml = Prism.languages.yaml;
Prism.languages.yml = Prism.languages.yaml;
2 changes: 1 addition & 1 deletion components/prism-yaml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions tests/languages/yaml/anchor_and_alias_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
x-number: &num-ber 13
x-string: &stri_ng "good"
x-null: &nu-ll null
toaster marked this conversation as resolved.
Show resolved Hide resolved
x-boolean: &boo-lean true
x-datetime: &date-time 2001-12-15T02:59:43.1Z
x-scalar: &sca-lar |
foo
bar

foobar: *num-ber
fubar: *stri_ng
toaster marked this conversation as resolved.
Show resolved Hide resolved

----------------------------------------------------

[
["key", "x-number"],
["punctuation", ":"],
["important", "&num-ber"],
["number", "13"],

["key", "x-string"],
["punctuation", ":"],
["important", "&stri_ng"],
["string", "\"good\""],

["key", "x-null"],
["punctuation", ":"],
["important", "&nu-ll"],
["null", "null"],

["key", "x-boolean"],
["punctuation", ":"],
["important", "&boo-lean"],
["boolean", "true"],

["key", "x-datetime"],
["punctuation", ":"],
["important", "&date-time"],
["datetime", "2001-12-15T02:59:43.1Z"],

["key", "x-scalar"],
["punctuation", ":"],
["important", "&sca-lar"],
["punctuation", "|"],
["scalar", "\n foo\n bar"],

["key", "foobar"],
["punctuation", ":"],
["important", "*num-ber"],

["key", "fubar"],
["punctuation", ":"],
["important", "*stri_ng"]
]

----------------------------------------------------

Checks for anchors and aliases.
TODO: null, boolean, datetime, scalar