Have you looked at String.highlights
Italicised and bolded text arenât findable in the same manner. But as you only use 2 colours at present, you could easily adapt your method to use 2 of the 3 highlight colours you donât currently use, and then you can extract the 4 different types of âhighlightâ you are applying.
Even then, String.highlights returns a list of highlights of all or a given colour. What you are presuming is an $Text stream output processor which is a feature request Iâve not previously seen. IOW, the $Text is rendered for export (or preview window) depending on where highlights are detected in $Text. At present, I donât think that a tractable approach in Tinderbox so, today, Iâd try an approach closer aligned to be queries can find.
IOW, I read that you want a putative stream processor to âreadâ the $Text and on encountering a highlight set the export code stream to enclose the highlight with an HTML heading level (dependent on the highlight colour?). Then in italic or bolded (or both?) are encountered export those $Text substrings as bulleted items
But, what defines under? For this this sort of logic to work, you need to address the edge cases. What happens if text occurs between the end of a highlighted substring and a bold/italic section. You logic doesnât account for that. Why are bold and italic both exporting to the same mark-up when they have been marked differently at source? And so on.
In terms of what you can do today consider using auto-headings instead (as well as?) coloured highlights.
HTH 