ccampbell / rainbow

Simple syntax highlighting library written in javascript
http://rainbowco.de
Apache License 2.0
3.3k stars 465 forks source link

Optionally support synchronous syntax highlighting #223

Open lucaswerkmeister opened 7 years ago

lucaswerkmeister commented 7 years ago

Since version 2, rainbow requires a Content-Security-Policy that allows blob: in workers, to support this:

const blob = new Blob([fullString], { type: 'text/javascript' });
return new Worker((window.URL || window.webkitURL).createObjectURL(blob));

With a more restrictive CSP, this results in a CSP error logged to the console, and preloading blocks that keep spinning forever. In this case, it would be nice to have an option to make Rainbow run the syntax highlighting synchronously instead of in a worker.

Feel free to suggest other solutions to the problem “Rainbow doesn’t work due to CSP”, of course… for example – is it really necessary to construct the worker script as a blob? Can’t it get the entire rainbow.js file?