OK. I have been playing and getting closer. When it works, I can replace <mark> with a span and class to style it in CSS (like bullfrog’s above). The following test HTML highlights the tags in a browser;
<!DOCTYPE html>
<html dir="auto">
<head>
<title>Test tag highlight</title>
<meta name="generator" content="DEVONthink 3.9"/>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', (event) => {
const term = "(\#[a-zA-Z0-9_]*)";
const RE = new RegExp(term, "g");
const html = document.body.innerHTML;
document.body.innerHTML = html.replaceAll(RE, "<mark>$1</mark>");
});
</script>
<meta charset="utf-8"/>
</head>
<body>
<h1>Test tag format</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In nisl nisi scelerisque eu. Dictum sit amet justo donec. Quis auctor elit sed vulputate mi sit amet mauris commodo. Proin sed .</p>
<p>#test #testx #23test</p>
</body>
</html>
You get the tags highlighted. If I put the script part into my markdown document in DTP and click preview it also works.
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const term = "(\#[a-zA-Z0-9_]*)";
const RE = new RegExp(term, "g");
const html = document.body.innerHTML;
document.body.innerHTML = html.replaceAll(RE, "<mark>$1</mark>");
});
</script>
# Test tag format
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In nisl nisi scelerisque eu. Dictum sit amet justo donec. Quis auctor elit sed vulputate mi sit amet mauris commodo. Proin sed.
#test #testx #23test
However if I put the code in a text document linked to the preferences>files>markdown>javascript it doesn’t work.
What am I doing wrong? Any help gratefully received.
FYI text document:
document.addEventListener('DOMContentLoaded', (event) => {
const term = "(\#[a-zA-Z0-9_]*)";
const RE = new RegExp(term, "g");
const html = document.body.innerHTML;
document.body.innerHTML = html.replaceAll(RE, "<mark>$1</mark>");
});