wooorm / refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism
MIT License
724 stars 34 forks source link

Have a chance to lazy initialize refractor #10

Closed otakustay closed 6 years ago

otakustay commented 6 years ago

PrismJS itself contains a bunch of predefined behaviors, for example it automatically listen the message event when in a web worker, these behaviors can be disabled via global flags such as self.disableWorkerMessageHandler = true;

With refractor it initialize a PrismJS instance when module is imported, we don't have a good chance to set these flags when use es modules, so some lazy initialization would be very helpful:

import createRefractor from 'refractor/lazy';

self.disableWorkerMessageHandler = true;

const refractor = createRefractor();
refractor.highlight(code, language);
wooorm commented 6 years ago

I believe there’s only one option like that, disableWorkerMessageHandler. Manual is used internally already. Do workers actually work? Can we always turn them off?

otakustay commented 6 years ago

I strongly recommend refractor to disable Prism's web worker mode by default, the web worker mode only provides Prism's core functionality but not a virtual dom based solution

wooorm commented 6 years ago

Could you do a PR then?