Skip to content

Commit e050210

Browse files
committed
Revert adding named tag handles, since they are captured by the local tag handles
1 parent f6bcb34 commit e050210

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/languages/yaml.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ Category: common, config
1010
export 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 + '$',

test/markup/yaml/tag.expect.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
<span class="hljs-attr">key:</span> <span class="hljs-type">!!python/name:module.name</span> <span class="hljs-string">test</span>
77
<span class="hljs-attr">key:</span> <span class="hljs-type">!foo2.bar</span> <span class="hljs-string">test</span>
88
<span class="hljs-attr">key:</span> <span class="hljs-type">!(foo.bar?):tag</span> <span class="hljs-string">test</span>
9-
<span class="hljs-attr">key:</span> <span class="hljs-type">!foo!bar</span> <span class="hljs-string">test</span>

test/markup/yaml/tag.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ key: !!python/dict test
66
key: !!python/name:module.name test
77
key: !foo2.bar test
88
key: !(foo.bar?):tag test
9-
key: !foo!bar test

0 commit comments

Comments
 (0)