API to highlight any text, no inserting HTML tag

I think such API will be useful for:

  • TTS Addons
  • Note taking addons

Current solusions used by some addons is adding <span>:

<p>Shall I compare thee to summer' s day
Thou art more lovely and more temperate . </p>
<p>Shall I compare thee to summer' s day
<span>Thou art</span> more lovely and more temperate . </p>

That works but may cause web broken.

The built-in Find feature, and the Firefox-only Find API, have this superpower, but of course they cannot highlight the results of multiple queries simultaneously. I wonder how difficult it would be to do this? (I have no idea how it works…)