Some way to wrap any html element with another element?
<p>The message is submited via form. It can contain <strong>html</strong> as well as <strong>normal text</strong>.</p>

<p>i.e.:</p>

<pre><code>Why this code doesn't work for me?

&lt;script type="text/javascript"&gt;
    var _gaq = _gaq || [];

    _gaq.push(['_setAccount', 'UA-XXXXX-X']);

    _gaq.push(['_trackPageview']);

    (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
&lt;/script&gt;
</code></pre>

<p>I would like to surround html element with <code>pre</code> tag.</p>

<p>i.e.</p>

<pre><code>Why this code doesn't work for me?

&lt;pre&gt;
    &lt;script type="text/javascript"&gt;
        var _gaq = _gaq || [];

        _gaq.push(['_setAccount', 'UA-XXXXX-X']);

        _gaq.push(['_trackPageview']);

        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    &lt;/script&gt;
&lt;/pre&gt;
</code></pre>

<p>I asked earlier about it in php chat room and author of the answer in this question suggested to read the solution: <a href="http://stackoverflow.com/questions/5416924/php-domdocument-complete-transform-of-form-element-wrapping-and-removing">php DOMDocument: complete transform of form element? wrapping and removing?</a></p>

<p>Everything is perfect in this example exept few things. I need to wrap any html element obviously exept <code>pre</code> itself.  </p>

<ol>
<li>If elements are folded, then wrap only outer element.</li>
<li>If they are separate, then wrap each of them.</li>
<li>If there is only open tag, then wrap it only(no need of fixing with close tag).</li>
</ol>

<p>Does anyone have any possible idea for a solution to this question?
Thanks in advance to all who can help.</p>
