Sentece: ich fand
Word: finden
info: findet · fand · hat gefunden
i need a script to do this:
ich fand
Sentece: ich fand
Word: finden
info: findet · fand · hat gefunden
i need a script to do this:
ich fand
You could place your target word in a separate field with individual css styling. What is your workflow? If you create each note manually, styling the word is just two keyboard shortcuts away. If you import lots of vocabulary you could apply the styling using html tags beforehand.
i need a JavaScript code with Regex to do this:
Bolding word in sentence when this word matching with Word field or info field
Maybe something like this (created with ChatGPT)
<div>
Sentence: <span id="sentence">{{Sentence}}</span><br>
Word: <span id="word">{{Word}}</span><br>
Info: <span id="info">{{Info}}</span>
</div>
<script>
(function() {
const sentenceElement = document.getElementById('sentence');
const wordElement = document.getElementById('word');
const infoElement = document.getElementById('info');
const sentence = sentenceElement.textContent;
const word = wordElement.textContent;
const info = infoElement.textContent;
function splitBySeparators(string, separators) {
const regex = new RegExp(`[${separators.join('\\')}]+`);
return string.split(regex).map(s => s.trim());
}
const separators = ['·', ',', ';', ' '];
const wordsToMatch = [word, ...splitBySeparators(info, separators)];
const sentenceWords = splitBySeparators(sentence, separators);
const highlightedWords = sentenceWords.map(sentenceWord => {
if (wordsToMatch.includes(sentenceWord)) {
return `<span style="font-weight:bold;">${sentenceWord}</span>`;
} else {
return sentenceWord;
}
});
sentenceElement.innerHTML = highlightedWords.join(' ');
})();
</script>
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.