@@ -10,9 +10,12 @@ Category: common, config
1010export default function ( hljs ) {
1111 var LITERALS = 'true false yes no null' ;
1212
13- // YAML spec allows most URI characters as a part of tags.
14- // see https://yaml.org/spec/1.2/spec.html#id2764295
15- var YAML_TAG_RE = '[\\w#;/?:@&=+$,.~*\\\'()[\\]]+'
13+ // YAML spec allows non-reserved characters in tags, since they are intended
14+ // to be used sometimes as URIs. In order to differentiate between "local"
15+ // tags, prefixed with `!` and global tags, prefixed with `!!`, don't allow
16+ // the prefix char `!` in the first char of the expression.
17+ var NON_EXCLAMATION_CHARS = '\\w#;/?:@&=+$,.~*\\\'()[\\]'
18+ var YAML_TAG_RE = '[' + NON_EXCLAMATION_CHARS + '][' + NON_EXCLAMATION_CHARS + '!]*'
1619
1720 // Define keys as starting with a word character
1821 // ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
@@ -74,18 +77,14 @@ export default function(hljs) {
7477 excludeEnd : true ,
7578 relevance : 0
7679 } ,
77- { // "named" tags
80+ { // local tags
7881 className : 'type' ,
79- begin : '!\w+! ' + YAML_TAG_RE ,
82+ begin : '!' + YAML_TAG_RE ,
8083 } ,
81- { // "global" tags ( data types)
84+ { // data type
8285 className : 'type' ,
8386 begin : '!!' + YAML_TAG_RE ,
8487 } ,
85- { // local tags
86- className : 'type' ,
87- begin : '!' + YAML_TAG_RE ,
88- } ,
8988 { // fragment id &ref
9089 className : 'meta' ,
9190 begin : '&' + hljs . UNDERSCORE_IDENT_RE + '$' ,
0 commit comments