Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Version 10.1.0 (in progress)

Language improvements:

- fix(yaml) Fix tags to include non-word characters (#2486) [Peter Plantinga][]

[Peter Plantinga]: https://github.com/pplantinga


## Version 10.0.1

Parser Engine Changes:
Expand Down
20 changes: 16 additions & 4 deletions src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Category: common, config
export default function(hljs) {
var LITERALS = 'true false yes no null';

// 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
// ...and ending with a colon followed immediately by a space, tab or newline.
Expand Down Expand Up @@ -79,13 +82,22 @@ export default function(hljs) {
excludeEnd: true,
relevance: 0
},
{ // local tags
{ // named tags
className: 'type',
begin: '!\\w+!' + URI_CHARACTERS,
},
// https://yaml.org/spec/1.2/spec.html#id2784064
{ // verbatim tags
className: 'type',
begin: '!<' + URI_CHARACTERS + ">",
},
{ // primary tags
className: 'type',
begin: '!' + hljs.UNDERSCORE_IDENT_RE,
begin: '!' + URI_CHARACTERS,
},
{ // data type
{ // secondary tags
className: 'type',
begin: '!!' + hljs.UNDERSCORE_IDENT_RE,
begin: '!!' + URI_CHARACTERS,
},
{ // fragment id &ref
className: 'meta',
Expand Down
8 changes: 8 additions & 0 deletions test/markup/yaml/tag.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
<span class="hljs-attr">key:</span> <span class="hljs-type">!localtagname</span> <span class="hljs-string">test</span>
<span class="hljs-attr">key:</span> <span class="hljs-string">"!notatag"</span>
<span class="hljs-attr">key:</span> <span class="hljs-string">'!!notatageither'</span>
<span class="hljs-attr">key:</span> <span class="hljs-type">!!python/dict</span> <span class="hljs-string">test</span>
<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>

<span class="hljs-string">---</span> <span class="hljs-type">!&lt;tag:clarkevans.com,2002:invoice&gt;</span>
<span class="hljs-attr">invoice:</span> <span class="hljs-number">34843</span>
8 changes: 8 additions & 0 deletions test/markup/yaml/tag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ key: !!builtintagname test
key: !localtagname test
key: "!notatag"
key: '!!notatageither'
key: !!python/dict test
key: !!python/name:module.name test
key: !foo2.bar test
key: !(foo.bar?):tag test
key: !named!tag test

--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843