diff --git a/plugins/line-highlight/prism-line-highlight.js b/plugins/line-highlight/prism-line-highlight.js index 577d142e98..8d5faa156c 100644 --- a/plugins/line-highlight/prism-line-highlight.js +++ b/plugins/line-highlight/prism-line-highlight.js @@ -85,7 +85,7 @@ function applyHash() { var fakeTimer = 0; // Hack to limit the number of times applyHash() runs -Prism.hooks.add('after-highlight', function(env) { +Prism.hooks.add('complete', function(env) { var pre = env.element.parentNode; var lines = pre && pre.getAttribute('data-line'); diff --git a/plugins/line-numbers/prism-line-numbers.js b/plugins/line-numbers/prism-line-numbers.js index 9443deb7dc..5b01dceeae 100644 --- a/plugins/line-numbers/prism-line-numbers.js +++ b/plugins/line-numbers/prism-line-numbers.js @@ -1,4 +1,4 @@ -Prism.hooks.add('after-highlight', function (env) { +Prism.hooks.add('complete', function (env) { // works only for wrapped inside
 (not inline)
 	var pre = env.element.parentNode;
 	var clsReg = /\s*\bline-numbers\b\s*/;
@@ -10,6 +10,11 @@ Prism.hooks.add('after-highlight', function (env) {
 		return;
 	}
 
+	if ( env.element.querySelector(".line-numbers-rows") ) {
+		// Abort if line numbers already exists
+		return;
+	}
+
 	if (clsReg.test(env.element.className)) {
 		// Remove the class "line-numbers" from the 
 		env.element.className = env.element.className.replace(clsReg, '');
diff --git a/prism.js b/prism.js
index 8282b57193..e6a2273c4b 100644
--- a/prism.js
+++ b/prism.js
@@ -177,10 +177,6 @@ var _ = _self.Prism = {
 			parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
 		}
 
-		if (!grammar) {
-			return;
-		}
-
 		var code = element.textContent;
 
 		if(!code) {
@@ -196,6 +192,11 @@ var _ = _self.Prism = {
 			code: code
 		};
 
+		if (!grammar) {
+			_.hooks.run('complete', env);
+			return;
+		}
+
 		_.hooks.run('before-highlight', env);
 
 		if (async && _self.Worker) {
@@ -228,6 +229,9 @@ var _ = _self.Prism = {
 
 			_.hooks.run('after-highlight', env);
 		}
+
+		_.hooks.run('complete', env);
+
 	},
 
 	highlight: function (text, grammar, language) {