Okay I decided that I need to stop suffering so, can anyone help me? I were trying new things and solved the most important that was about import JSON. But yeah, it caused a problem. class keyword, it as caused a complete bug that I can't understand why happens.
This is my JS.
// Imports
import * as keyword from '../assets/keys.json' assert { type: "json" };
// Highlighter
function highlight(target) {
const targets = document.querySelectorAll(target);
const kws = keyword.default.js;
const kw = new RegExp(`\\b(${kws.join('|')})\\b(?<!(\\/\\/.*|\\/\\*[^]*?\\*\\/))`, 'g');
const str = /(['"`])(?:(?!\1)[^\\]|\.|\1)\1/g;
const com = /\/\/.*|\/\*[^]*?\*\//g;
const fn = /\w+\s*(?=\([^]*\)\s*\{)|(?<=\.)\s*\w+\s*(?=\([^]*\))|(?<=\()\w+\s*/g;
targets.forEach(targ => {
let content = targ.innerHTML;
content = content.replace(str, `<i class="str">$&</i>`);
content = content.replace(kw, `<i class="kw">$&</i>`);
content = content.replace(com, `<i class="com">$&</i>`);
content = content.replace(fn, `<i class="fn">$&</i>`);
targ.innerHTML = content;
});
}
// Apply
highlight('.output');
I've handled to stop it bug more than it was but now strings doesn't get the <i> element with his correspondent class. Any help would be thanked.
