Skip to content

Commit a2a2c16

Browse files
committed
Add named tag again
1 parent e050210 commit a2a2c16

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/languages/yaml.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ Category: common, config
1010
export default function(hljs) {
1111
var LITERALS = 'true false yes no null';
1212

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 + '!]*'
13+
// YAML spec allows non-reserved URI characters in tags.
14+
var URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\\\'()[\\]]+'
1915

2016
// Define keys as starting with a word character
2117
// ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
@@ -77,13 +73,17 @@ export default function(hljs) {
7773
excludeEnd: true,
7874
relevance: 0
7975
},
76+
{ // named tags
77+
className: 'type',
78+
begin: '!\\w+!' + URI_CHARACTERS,
79+
},
8080
{ // local tags
8181
className: 'type',
82-
begin: '!' + YAML_TAG_RE,
82+
begin: '!' + URI_CHARACTERS,
8383
},
8484
{ // data type
8585
className: 'type',
86-
begin: '!!' + YAML_TAG_RE,
86+
begin: '!!' + URI_CHARACTERS,
8787
},
8888
{ // fragment id &ref
8989
className: 'meta',

test/markup/yaml/tag.expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
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">!named!tag</span> <span class="hljs-string">test</span>

test/markup/yaml/tag.txt

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

0 commit comments

Comments
 (0)