In stock PHP5, what is a good preg_replace
expression for making this transformation:
replace newlines with <br />
, but only within <pre>
blocks
(Feel free to make simplifying assumptions, and ignore corner cases. For example, we can assume that tags will be one line, and not pathological things like )
Input text:
<div><pre class='some class'>1
2
3
</pre>
<pre>line 1
line 2
line 3
</pre>
</div>
Output:
<div><pre>1<br />2<br />3<br /></pre>
<pre>line 1<br />line 2<br />line 3<br /></pre>
</div>
(Motivating context: trying to close out bug 20760 in a wikimedia SyntaxHighlight_GeSHI extension, and finding the my PHP skills (I mostly do python) aren't up to snuff).
I'm open to other solutions, besides regexen, but small is preferred (as an example, building html parse machinery is overkill).