Skip to content

Commit

Permalink
Fix complete hook behaviour + run gulp task
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Aug 13, 2015
1 parent e58b6c0 commit fd54995
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
21 changes: 11 additions & 10 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,24 @@ var _ = _self.Prism = {
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
}

if (!grammar) {
return;
}

var code = element.textContent;

if(!code) {
return;
}

code = code.replace(/^(?:\r?\n|\r)/,'');

var env = {
element: element,
language: language,
grammar: grammar,
code: code
};

if(code) {
env.code = code.replace(/^(?:\r?\n|\r)/, '');
}

if (!code || !grammar) {
_.hooks.run('complete', env);
return;
}

_.hooks.run('before-highlight', env);

if (async && _self.Worker) {
Expand All @@ -205,6 +204,7 @@ var _ = _self.Prism = {

callback && callback.call(env.element);
_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
};

worker.postMessage(JSON.stringify({
Expand All @@ -222,6 +222,7 @@ var _ = _self.Prism = {
callback && callback.call(element);

_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
}
},

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.

2 changes: 1 addition & 1 deletion plugins/line-highlight/prism-line-highlight.min.js

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

6 changes: 6 additions & 0 deletions plugins/line-numbers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ <h2>CSS</h2>
<h2>HTML</h2>
<p>Please note the <code>data-start="-5"</code> in the code below.</p>
<pre class="line-numbers" data-src="plugins/line-numbers/index.html" data-start="-5"></pre>

<h2>Unknown languages</h2>
<pre class="language-none line-numbers"><code>This raw text
is not highlighted
but it still has
lines numbers</code></pre>
</section>

<footer data-src="templates/footer.html" data-type="text/html"></footer>
Expand Down
2 changes: 1 addition & 1 deletion plugins/line-numbers/prism-line-numbers.min.js

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

17 changes: 7 additions & 10 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,18 @@ var _ = _self.Prism = {

var code = element.textContent;

if(!code) {
return;
}

code = code.replace(/^(?:\r?\n|\r)/,'');

var env = {
element: element,
language: language,
grammar: grammar,
code: code
};

if (!grammar) {
if(code) {
env.code = code.replace(/^(?:\r?\n|\r)/, '');
}

if (!code || !grammar) {
_.hooks.run('complete', env);
return;
}
Expand All @@ -211,6 +209,7 @@ var _ = _self.Prism = {

callback && callback.call(env.element);
_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
};

worker.postMessage(JSON.stringify({
Expand All @@ -228,10 +227,8 @@ var _ = _self.Prism = {
callback && callback.call(element);

_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
}

_.hooks.run('complete', env);

},

highlight: function (text, grammar, language) {
Expand Down

0 comments on commit fd54995

Please sign in to comment.