Skip to content

Commit

Permalink
apply to ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Mar 3, 2020
1 parent 2978c8b commit 52beaf2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/languages/c-like.js
Expand Up @@ -32,10 +32,6 @@ export default function(hljs) {
// https://en.cppreference.com/w/cpp/language/escape
// \\ \x \xFF \u2837 \u00323747 \374
var CHARACTER_ESCAPES = '\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)'
var END_GROUP_SAME_AS_BEGIN = {
'after:begin': (m, resp) => { resp.data.heredoc = m[1]; },
'before:end': (m, resp) => { if (resp.data.heredoc !== m[1]) resp.ignoreMatch(); }
};
var STRINGS = {
className: 'string',
variants: [
Expand All @@ -51,7 +47,7 @@ export default function(hljs) {
Object.assign({
begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
end: /\)([^()\\ ]{0,16})"/,
}, END_GROUP_SAME_AS_BEGIN)
}, hljs.END_FIRST_MATCH_SAME_AS_BEGIN)
]
};

Expand Down
6 changes: 3 additions & 3 deletions src/languages/ruby.js
Expand Up @@ -72,10 +72,10 @@ export default function(hljs) {
returnBegin: true,
contains: [
{ begin: /<<[-~]?'?/ },
{ begin: /\w+/,
endSameAsBegin: true,
Object.assign({
begin: /(\w+)/, end: /(\w+)/,
contains: [hljs.BACKSLASH_ESCAPE, SUBST],
}
}, hljs.END_FIRST_MATCH_SAME_AS_BEGIN)
]
}
]
Expand Down
5 changes: 5 additions & 0 deletions src/lib/modes.js
Expand Up @@ -112,3 +112,8 @@ export const METHOD_GUARD = {
begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
relevance: 0
};

export const END_FIRST_MATCH_SAME_AS_BEGIN = {
'after:begin': (m, resp) => { resp.data.heredoc = m[1]; },
'before:end': (m, resp) => { if (resp.data.heredoc !== m[1]) resp.ignoreMatch(); }
};

0 comments on commit 52beaf2

Please sign in to comment.