diff --git a/CHANGES.md b/CHANGES.md
index a36b69e06f..f77c7baadb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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:
diff --git a/src/languages/yaml.js b/src/languages/yaml.js
index d7586eb1f3..4fc4ba0a28 100644
--- a/src/languages/yaml.js
+++ b/src/languages/yaml.js
@@ -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.
@@ -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',
diff --git a/test/markup/yaml/tag.expect.txt b/test/markup/yaml/tag.expect.txt
index dbc5645dcd..87168452e3 100644
--- a/test/markup/yaml/tag.expect.txt
+++ b/test/markup/yaml/tag.expect.txt
@@ -2,3 +2,11 @@
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
diff --git a/test/markup/yaml/tag.txt b/test/markup/yaml/tag.txt
index 35f361543d..20ee84a731 100644
--- a/test/markup/yaml/tag.txt
+++ b/test/markup/yaml/tag.txt
@@ -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
+
+--- !
+invoice: 34843