Automatically highlight user-defined text with Seek function (2019-09-22)
< Обсуждения Text Highlight and Seek
Sorry, this is due to the design of the script. It doesn't search across node boundaries, it checks each text node individually. So as written, it doesn't view the F: and 24 as being in the same run of text:
<p>F: 63 / F: <strong>24</strong></p>
That's obviously different from how we think about inline formatting, but unfortunately, I don't know enough about XPath syntax to suggest a way to modify the script to work around this.
What do you think about removing the bold from the text as a workaround?
Unfortunately I'm not in control of the source data.
Thank you very much for the response though Jefferson! It was driving me crazy, I can relax now :)
What I had in mind about removing the bold was -- assuming you have a safe copy of the original and it's okay to modify the document -- to select the relevant area of text and run some code like the following in Firefox's Web Console:
var sel = window.getSelection();
var rng = sel.getRangeAt([0]);
var cns = rng.commonAncestorContainer.childNodes;
for (var j=cns.length-1; j>0; j--){
if (cns[j].nodeType == 1 && ['STRONG', 'B'].includes(cns[j].nodeName)) {
cns[j-1].textContent += cns[j].textContent;
cns[j].remove();
}
}
That takes the text contents of each bold tag, copies it into the previous node, and then removes the bold tag. This allows the userscript to match up the parts.
Regex matching BOLD and non-bold characters, please help!
I'm really struggling with this!
I've tried everything I can think but I cannot get regex to match BOLD numbers following normal text. I can get it to match text separately, or numbers separately, but never together.
A: 25 / B: 73 F: 63 / F: 24 I: 33 / F: 85 F: 54 / Q: 53
In the above example I'd like to highlight only the numbers, greater than 50 that follow "F:". There are 3 times this should trigger (Left side on line 2 and 4, right side line 3), however it seems to ignore the times it's bold!
Using something such as:
F:\s([5-9]\d)
Will highlight the followingA: 25 / B: 73 F: 63(highlighted) / F: 24 I: 33 / F: 85 (IGNORED!) F: 54(highlighted) / Q: 53.
Please someone with a better brain than mine help!