tbranyen/diffhtml

Comment inside script tag

rzhornyk opened this issue · 4 comments

We use script tag to save mustache templates. Our backend generate automatically comments tag inside.
Here simplified markup:

<script type="template/mustache" data-ref="galleryTemplate">
        <div
            class="b-product_gallery-inner"
            data-ref="carouselInner"
        >
             <!-- dwMarker="linclude" dwTemplateTitle="" dwTemplateURL="" -->
   
        </div>
</script>

This comment and logic around "doctypeEx" variable in parse.js file cause script node to become empty because comment match doctype regexp and skip adding text element inside script.

Here is suggested fix #206

HTML comment syntax is also valid JS syntax, so this is a good catch! I'm writing a test now to validate this fixes it as expected. Thanks!

I wrote a test to validate the fix and I'm unable to get it to work. I think we may need a few additional changes to fully support this feature.

    it('will support HTML comments inside script tags', () => {
      const vTree = parse('<script>before<!-- in -->after</script>').childNodes[0];
      equal(vTree.nodeValue, 'before<!-- in -->after');
    });

Closed in #207