wooorm / refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Have a chance to lazy initialize refractor

otakustay opened this issue · comments

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);
commented

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?

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

commented

Could you do a PR then?