Skip to content

Commit

Permalink
insertBefore now correctly updates references (#1531)
Browse files Browse the repository at this point in the history
Removes some workarounds for misplacing the reference when using `insertBefore`.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Aug 18, 2018
1 parent 9d15ff6 commit 9dfec34
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
7 changes: 5 additions & 2 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ var _ = _self.Prism = {
}
}

var old = root[inside];
root[inside] = ret;

// Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) {
if (value === root[inside] && key != inside) {
if (value === old && key != inside) {
this[key] = ret;
}
});

return root[inside] = ret;
return ret;
},

// Traverse a language definition with Depth First Search
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ Prism.languages.insertBefore('javascript', 'string', {
pattern: /^\${|}$/,
alias: 'punctuation'
},
rest: null // See below
rest: Prism.languages.javascript
}
},
'string': /[\s\S]+/
}
}
});
Prism.languages.javascript['template-string'].inside['interpolation'].inside.rest = Prism.languages.javascript;

if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
}
});

var string_interpolation = {
pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
lookbehind: true,
inside: {
rest: Prism.languages.php
}
};

Prism.languages.insertBefore('php', 'string', {
'nowdoc-string': {
pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
Expand Down Expand Up @@ -78,7 +86,7 @@
'punctuation': /^<<<"?|[";]$/
}
},
'interpolation': null // See below
'interpolation': string_interpolation // See below
}
},
'single-quoted-string': {
Expand All @@ -91,23 +99,13 @@
greedy: true,
alias: 'string',
inside: {
'interpolation': null // See below
'interpolation': string_interpolation // See below
}
}
});
// The different types of PHP strings "replace" the C-like standard string
delete Prism.languages.php['string'];

var string_interpolation = {
pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
lookbehind: true,
inside: {
rest: Prism.languages.php
}
};
Prism.languages.php['heredoc-string'].inside['interpolation'] = string_interpolation;
Prism.languages.php['double-quoted-string'].inside['interpolation'] = string_interpolation;

Prism.hooks.add('before-tokenize', function(env) {
if (!/(?:<\?php|<\?)/ig.test(env.code)) {
return;
Expand Down
Loading

0 comments on commit 9dfec34

Please sign in to comment.