Skip to content

Commit

Permalink
Revert #998 + run normalize-whitespace and remove-initial-line-feed p…
Browse files Browse the repository at this point in the history
…lugins in the before-sanity-check hook. Fix #1018 (see issue for discussion)
  • Loading branch information
Golmote committed Sep 1, 2016
1 parent f138f8f commit 86aa3d2
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 7 deletions.
9 changes: 9 additions & 0 deletions components/prism-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@

env.tokenStack = [];

env.backupCode = env.code;
env.code = env.code.replace(handlebars_pattern, function(match) {
env.tokenStack.push(match);

return '___HANDLEBARS' + env.tokenStack.length + '___';
});
});

// Restore env.code for other plugins (e.g. line-numbers)
Prism.hooks.add('before-insert', function(env) {
if (env.language === 'handlebars') {
env.code = env.backupCode;
delete env.backupCode;
}
});

// Re-insert the tokens after highlighting
// and highlight them with defined grammar
Prism.hooks.add('after-highlight', function(env) {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-handlebars.min.js

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

9 changes: 9 additions & 0 deletions components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,22 @@ if (Prism.languages.markup) {

env.tokenStack = [];

env.backupCode = env.code;
env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {
env.tokenStack.push(match);

return '{{{PHP' + env.tokenStack.length + '}}}';
});
});

// Restore env.code for other plugins (e.g. line-numbers)
Prism.hooks.add('before-insert', function(env) {
if (env.language === 'php') {
env.code = env.backupCode;
delete env.backupCode;
}
});

// Re-insert the tokens after highlighting
Prism.hooks.add('after-highlight', function(env) {
if (env.language !== 'php') {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-php.min.js

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

9 changes: 9 additions & 0 deletions components/prism-smarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

env.tokenStack = [];

env.backupCode = env.code;
env.code = env.code.replace(smarty_pattern, function(match) {

// Smarty tags inside {literal} block are ignored
Expand All @@ -100,6 +101,14 @@
});
});

// Restore env.code for other plugins (e.g. line-numbers)
Prism.hooks.add('before-insert', function(env) {
if (env.language === 'smarty') {
env.code = env.backupCode;
delete env.backupCode;
}
});

// Re-insert the tokens after highlighting
// and highlight them with defined grammar
Prism.hooks.add('after-highlight', function(env) {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-smarty.min.js

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

2 changes: 1 addition & 1 deletion plugins/normalize-whitespace/prism-normalize-whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Prism.plugins.NormalizeWhitespace = new NormalizeWhitespace({
'spaces-to-tabs': 4*/
});

Prism.hooks.add('before-highlight', function (env) {
Prism.hooks.add('before-sanity-check', function (env) {
var pre = env.element.parentNode;
var clsReg = /\bno-whitespace-normalization\b/;
if (!env.code || !pre || pre.nodeName.toLowerCase() !== 'pre' ||
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
return;
}

Prism.hooks.add('before-highlight', function (env) {
Prism.hooks.add('before-sanity-check', function (env) {
if (env.code) {
var pre = env.element.parentNode;
var clsReg = /\s*\bkeep-initial-line-feed\b\s*/;
Expand Down

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

0 comments on commit 86aa3d2

Please sign in to comment.