Платформа ЦРНП "Мирокод" для разработки проектов
https://git.mirocod.ru
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
693 B
19 lines
693 B
export default async function highlight(elementOrNodeList) { |
|
if (!window.config || !window.config.HighlightJS || !elementOrNodeList) return; |
|
const nodes = 'length' in elementOrNodeList ? elementOrNodeList : [elementOrNodeList]; |
|
if (!nodes.length) return; |
|
|
|
const {default: Worker} = await import(/* webpackChunkName: "highlight" */'./highlight.worker.js'); |
|
const worker = new Worker(); |
|
|
|
worker.addEventListener('message', ({data}) => { |
|
const {index, html} = data; |
|
nodes[index].outerHTML = html; |
|
}); |
|
|
|
for (let index = 0; index < nodes.length; index++) { |
|
const node = nodes[index]; |
|
if (!node) continue; |
|
worker.postMessage({index, html: node.outerHTML}); |
|
} |
|
}
|
|
|