(transformHooks: ITransformHooks)
| 8 | name, |
| 9 | config, |
| 10 | transform(transformHooks: ITransformHooks) { |
| 11 | let loading: Promise<void>; |
| 12 | const preloadScripts = |
| 13 | plugin.config?.preloadScripts?.map((item) => |
| 14 | patchJSItem(transformHooks.transformer.urlBuilder, item), |
| 15 | ) || []; |
| 16 | const autoload = () => { |
| 17 | loading ||= loadJS(preloadScripts); |
| 18 | return loading; |
| 19 | }; |
| 20 | |
| 21 | let enableFeature = noop; |
| 22 | transformHooks.parser.tap((md) => { |
| 23 | md.set({ |
| 24 | highlight: (str: string, language?: string) => { |
| 25 | enableFeature(); |
| 26 | const { hljs } = window; |
| 27 | if (hljs) { |
| 28 | return hljs.highlightAuto(str, language ? [language] : undefined) |
| 29 | .value; |
| 30 | } |
| 31 | autoload().then(() => { |
| 32 | transformHooks.retransform.call(); |
| 33 | }); |
| 34 | return str; |
| 35 | }, |
| 36 | }); |
| 37 | }); |
| 38 | transformHooks.beforeParse.tap((_, context) => { |
| 39 | enableFeature = () => { |
| 40 | context.features[name] = true; |
| 41 | }; |
| 42 | }); |
| 43 | return { |
| 44 | styles: plugin.config?.styles, |
| 45 | }; |
| 46 | }, |
| 47 | }); |
| 48 | |
| 49 | export default plugin; |
nothing calls this directly
no test coverage detected