I’m writing a script to catch certain strings inside [data-refs-self*='parsing'], based on this. It’s in my custom.js:
function syntaxHighlights() {
var ca = document.querySelectorAll("[data-refs-self*='parsing']");
for(var i=0; i < ca.length; i++) {
var data = ca[i].innerHTML;
data = data.replace(/test/g, '<span class="testclass">test</span>');
ca[i].innerHTML = data;
}
}
window.addEventListener("load", syntaxHighlights);
with a formatting style in custom.css:
.testclass {
color: red;
}
I have restarted, reloaded, and refreshed the app, but the script isn’t doing anything to the string test in the block that is tagged with #parsing. What am I doing wrong?
I’ve also been unable to get custom.js to do anything. I think there’s an issue with it simply not loading the Javascript file. Do you get a pop-up asking you for permission to run the script?
Thanks @charliie, as @danzu mentioned–there was actually a bug in Logseq that was preventing custom.js from being loaded. It was fixed in 0.59. You can now just write javascript in custom.js, restart Logseq, and it will prompt you to run it–no plugin necessary.