Skip to content

Commit

Permalink
Add named tag again
Browse files Browse the repository at this point in the history
  • Loading branch information
pplantinga committed Apr 18, 2020
1 parent e050210 commit a2a2c16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ Category: common, config
export default function(hljs) {
var LITERALS = 'true false yes no null';

// YAML spec allows non-reserved characters in tags, since they are intended
// to be used sometimes as URIs. In order to differentiate between "local"
// tags, prefixed with `!` and global tags, prefixed with `!!`, don't allow
// the prefix char `!` in the first char of the expression.
var NON_EXCLAMATION_CHARS = '\\w#;/?:@&=+$,.~*\\\'()[\\]'
var YAML_TAG_RE = '[' + NON_EXCLAMATION_CHARS + '][' + NON_EXCLAMATION_CHARS + '!]*'
// YAML spec allows non-reserved URI characters in tags.
var URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\\\'()[\\]]+'

// Define keys as starting with a word character
// ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
Expand Down Expand Up @@ -77,13 +73,17 @@ export default function(hljs) {
excludeEnd: true,
relevance: 0
},
{ // named tags
className: 'type',
begin: '!\\w+!' + URI_CHARACTERS,
},
{ // local tags
className: 'type',
begin: '!' + YAML_TAG_RE,
begin: '!' + URI_CHARACTERS,
},
{ // data type
className: 'type',
begin: '!!' + YAML_TAG_RE,
begin: '!!' + URI_CHARACTERS,
},
{ // fragment id &ref
className: 'meta',
Expand Down
1 change: 1 addition & 0 deletions test/markup/yaml/tag.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<span class="hljs-attr">key:</span> <span class="hljs-type">!!python/name:module.name</span> <span class="hljs-string">test</span>
<span class="hljs-attr">key:</span> <span class="hljs-type">!foo2.bar</span> <span class="hljs-string">test</span>
<span class="hljs-attr">key:</span> <span class="hljs-type">!(foo.bar?):tag</span> <span class="hljs-string">test</span>
<span class="hljs-attr">key:</span> <span class="hljs-type">!named!tag</span> <span class="hljs-string">test</span>
1 change: 1 addition & 0 deletions test/markup/yaml/tag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ key: !!python/dict test
key: !!python/name:module.name test
key: !foo2.bar test
key: !(foo.bar?):tag test
key: !named!tag test

0 comments on commit a2a2c16

Please sign in to comment.