zachofalltrades/jquery.format

<img> tag without a closing slash causes incorrect indentation on subsequent tags

Opened this issue · 0 comments

Steps to reproduce:

$.format("<div><div><img ></div></div>")

Actual Output:

<div>
    <div>
        <img >
        </div>
    </div>

Expected Output:

<div>
    <div>
        <img >
    </div>
</div>

Workaround:

I was able to naively workaround this by doing a replace on the string before passing it to format():

var input = "<div><div><img ></div></div>";
$.format(input.replace( /<img\s*([^>]*)>/g, "<img $1 />" ))

But this is fragile and doesn't address other tags that might also not have a closing slash.