brian-girko / multiple-highlight

Color-coded highlighter extension to find queries
https://add0n.com/multiple-highlight.html
23 stars 4 forks source link

Regular expression only works if matches exist within a single DOM node #27

Open Nezteb opened 2 years ago

Nezteb commented 2 years ago

Example:

Expected behavior:

Actual behavior:

That being said, I acknowledge this might be an unrealistic goal. The HTML for that particular GitHub code line looks like:

<td id="LC2" class="blob-code blob-code-inner js-file-line rgh-linkified-code rgh-seen-13226903565">
  <span class="pl-ent">"private"</span>:
  <span class="pl-c1">true</span>,
</td>

One option might be something like:

> const regex = /private.*/g # insert whatever regex here
  const bodyString = document.getElementsByTagName("body")[0].textContent
  const results = [...bodyString.matchAll(regex)]
  results.join("")

'private": true,'

I don't know if this would work in all scenarios, but it could be a configurable search option? Something like a checkbox for searchTextContent: true | false?