I've been looking at "hidden messages" in posts lately, where the question appears to read, for instance
Should I use or ?
and the real question becomes visible only when editing:
Should I use <span> or <div>?
Of course it's not difficult to add backticks to this line manually, but when a very long post contains a lot of these, with regular HTML code blocks in between, it is a lot of work.
So I thought I was smart and copied the message source into my text editor and write a little regex to replace them all, but that's when the troubles started.
I mean, ^(<|[^ ].*[^`]<| [^ ].*[^`]<| [^ ].*[^`]<| [^ ].*[^`]<)[a-zA-Z/]
is not good enough!
It gives false positives for indented code blocks in quote blocks, like this
> <div>some html</div>
And it gives false negatives for where people are trying to indent a code block, but omit a blank line above:
My HTML looks like this:
<div>some html</div>
So, can anybody come up with a better regex? Or some other way of identifying the html that should appear as a code block within the post?