Browse Source

beforeHighlight callback

hakimel 3 years ago
parent
commit
ea14d4a08a
3 changed files with 13 additions and 4 deletions
  1. 0 0
      plugin/highlight/highlight.esm.js
  2. 0 0
      plugin/highlight/highlight.js
  3. 13 4
      plugin/highlight/plugin.js

File diff suppressed because it is too large
+ 0 - 0
plugin/highlight/highlight.esm.js


File diff suppressed because it is too large
+ 0 - 0
plugin/highlight/highlight.js


+ 13 - 4
plugin/highlight/plugin.js

@@ -30,6 +30,7 @@ const Plugin = {
 
 
 		// Read the plugin config options and provide fallbacks
 		// Read the plugin config options and provide fallbacks
 		let config = reveal.getConfig().highlight || {};
 		let config = reveal.getConfig().highlight || {};
+
 		config.highlightOnLoad = typeof config.highlightOnLoad === 'boolean' ? config.highlightOnLoad : true;
 		config.highlightOnLoad = typeof config.highlightOnLoad === 'boolean' ? config.highlightOnLoad : true;
 		config.escapeHTML = typeof config.escapeHTML === 'boolean' ? config.escapeHTML : true;
 		config.escapeHTML = typeof config.escapeHTML === 'boolean' ? config.escapeHTML : true;
 
 
@@ -61,12 +62,20 @@ const Plugin = {
 				hljs.highlightElement( event.currentTarget );
 				hljs.highlightElement( event.currentTarget );
 			}, false );
 			}, false );
 
 
-			if( config.highlightOnLoad ) {
-				Plugin.highlightBlock( block );
-			}
-
 		} );
 		} );
 
 
+		// Triggers a callback function before we trigger highlighting
+		if( typeof config.beforeHighlight === 'function' ) {
+			config.beforeHighlight( hljs );
+		}
+
+		// Run initial highlighting for all code
+		if( config.highlightOnLoad ) {
+			Array.from( reveal.getRevealElement().querySelectorAll( 'pre code' ) ).forEach( block => {
+				Plugin.highlightBlock( block );
+			} );
+		}
+
 		// If we're printing to PDF, scroll the code highlights of
 		// If we're printing to PDF, scroll the code highlights of
 		// all blocks in the deck into view at once
 		// all blocks in the deck into view at once
 		reveal.on( 'pdf-ready', function() {
 		reveal.on( 'pdf-ready', function() {

Some files were not shown because too many files changed in this diff