Fix mermaid highlight
Resolves https://github.com/matcornic/hugo-theme-learn/issues/235
Attempted to use https://github.com/vjeantet/hugo-theme-docdock/pull/113/files but that wasn't working
This seems to still be happening for me on the preview website. Searching for Alice is erasing that term from the sequence chart.
https://deploy-preview-300--learn.netlify.com/en/shortcodes/mermaid/
(Firefox 68)
Searching for Alice on this doesn't break it and actually works. The scope of this change seems fairly benign is there any reason this doesn't make life better for people instead of breaking pages?
something like this might work better to allow for subgraphs
if (match) {
if (
$(node).parents(".language-mermaid").length > 0 ||
$(node).parents(".mermaid").length > 0
) {
return 0;
}
var highlight = document.createElement(nodeName || 'span');
highlight.className = className || 'highlight';
var wordNode = node.splitText(match.index);
wordNode.splitText(match[0].length);
var wordClone = wordNode.cloneNode(true);
highlight.appendChild(wordClone);
wordNode.parentNode.replaceChild(highlight, wordNode);
return 1; //skip added node in parent
}
I provided a different more robust solution in #451