mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	This should eliminate page freezes when loading big files/diff. `highlightBlock` is needed to preserve existing nodes when highlighting and for that, highlight.js needs access to the DOM API so I added a DOM implementation to make it work, which adds around 300kB to the output file size of the lazy-loaded `highlight.js`. Co-authored-by: Lauris BH <lauris@nix.lv>
		
			
				
	
	
		
			13 lines
		
	
	
		
			360 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			13 lines
		
	
	
		
			360 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import {highlightBlock} from 'highlight.js';
 | 
						|
import {createWindow} from 'domino';
 | 
						|
 | 
						|
self.onmessage = function ({data}) {
 | 
						|
  const window = createWindow();
 | 
						|
  self.document = window.document;
 | 
						|
 | 
						|
  const {index, html} = data;
 | 
						|
  document.body.innerHTML = html;
 | 
						|
  highlightBlock(document.body.firstChild);
 | 
						|
  self.postMessage({index, html: document.body.innerHTML});
 | 
						|
};
 |