diff --git a/CHANGES.md b/CHANGES.md index 329d2c0e2c..5a869f2fb2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,6 +39,7 @@ Core Grammars: - fix(nix) handle backslash string escapes [h7x4][] - fix(nix) don't mix escapes for `"` and `''` strings [h7x4][] - fix(swift) - Fixed syntax highlighting for class func/var declarations [guuido] +- fix(yaml) - Fixed wrong escaping behavior in single quoted strings [guuido] New Grammars: diff --git a/src/languages/yaml.js b/src/languages/yaml.js index 9ddb1ba2e9..d0d0603cbc 100644 --- a/src/languages/yaml.js +++ b/src/languages/yaml.js @@ -42,14 +42,25 @@ export default function(hljs) { } ] }; + + const SINGLE_QUOTE_STRING = { + className: 'string', + relevance: 0, + begin: /'/, + end: /'/, + contains: [ + { + match: /''/, + scope: 'char.escape', + relevance: 0 + } + ] + }; + const STRING = { className: 'string', relevance: 0, variants: [ - { - begin: /'/, - end: /'/ - }, { begin: /"/, end: /"/ @@ -67,7 +78,13 @@ export default function(hljs) { const CONTAINER_STRING = hljs.inherit(STRING, { variants: [ { begin: /'/, - end: /'/ + end: /'/, + contains: [ + { + begin: /''/, + relevance: 0 + } + ] }, { begin: /"/, @@ -176,6 +193,7 @@ export default function(hljs) { }, OBJECT, ARRAY, + SINGLE_QUOTE_STRING, STRING ]; diff --git a/test/markup/yaml/string.expect.txt b/test/markup/yaml/string.expect.txt index 84899f239b..ede844b1e7 100644 --- a/test/markup/yaml/string.expect.txt +++ b/test/markup/yaml/string.expect.txt @@ -5,3 +5,11 @@ multi-string value key: true + +key: '\' +key: "\\" +key: "\" +key: value" +key: value +key: '''' +key: 'some''value' \ No newline at end of file diff --git a/test/markup/yaml/string.txt b/test/markup/yaml/string.txt index db9b38935d..64590ea6e9 100644 --- a/test/markup/yaml/string.txt +++ b/test/markup/yaml/string.txt @@ -5,3 +5,11 @@ key: | multi-string value key: true + +key: '\' +key: "\\" +key: "\" +key: value" +key: value +key: '''' +key: 'some''value'