How to fix wrong javascript after using Tidy

Almost every time when I updating something I become mean! In newest versions of Tidy (newest – 2015, lol) I found disappoint problem that javascript codes stopped working. Because Tidy converted javascript codes in page e. g.:

<script>
    script.onload = () => resolve(script);
</script>

To:

<script>
    <![CDATA[
            script.onload = () => resolve(script);
    ]]>
</script>

Instead of (in early versions):

<script>
    // <![CDATA[
            script.onload = () => resolve(script);
    // ]]>
</script>

If you have the same problem then don’t worry. Most likely Tidy tidying codes to xml or xhtml format default now. I found due solution this problem -- use option “output-html”:

$code = $tidy->repairString($code, [
    ...
    'output-html' => 1,
], 'utf8');
 20   24 d  
Popular