inikulin/parse5

Custom single closing tag can`t be parsed correctly

tclxjiaxing-huang opened this issue · 1 comments

when I use parse5 to pares follow code

<el-card>
        <el-divider />
        <el-row>
            <el-col>
                <div class="item-inner">
                </div>
            </el-col>
        </el-row>
        <el-divider border-style="dashed" />
        <div class="sub-header">
            <div class="t-small-title sub-title">something</div>
            <el-button text type="primary">something</el-button>
        </div>
</el-card>

the result is
image

you can see the tag el-row is in the tag el-divider, but in fact, the code meaning is el-rowand el-divider are at the same level
so I checked the source code, and find this code

function genericStartTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token: TagToken): void {
    p._reconstructActiveFormattingElements();
    p._insertElement(token, NS.HTML);
}

it didn`t handle the single closing tag, so I add follow code and work now!

function genericStartTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token: TagToken): void {
    p._reconstructActiveFormattingElements();

    if (token.selfClosing) {
        p._appendElement(token, NS.HTML);
        p.framesetOk = false;
        token.ackSelfClosing = true;
    } else {
        p._insertElement(token, NS.HTML);
    }
}

I don`t have permission to push branch, so can`t to push PR. I read the source code a lot, so I add the new code, you can check it, maybe somewhere I did`t notice.

sorry about my english~~

fb55 commented

Self-closing tags are not recognized in the HTML spec. Hence parse5 won't support them. Hope that makes sense!