[英]Convert open and close tag into self-close tag in Javasript
I am trying to compare two html files.我正在尝试比较两个 html 文件。 One file only uses self-close tag if the content is empty.
如果内容为空,一个文件仅使用自关闭标签。 The other one uses a mix of self-close tag and open-close tag.
另一种是混合使用自关闭标签和开-关标签。 I would like to convert all the open-close tags in the second file to be self-close tags so that the ending tags in the two html files are in the same format.
我想将第二个文件中的所有打开-关闭标签转换为自关闭标签,以便两个 html 文件中的结束标签格式相同。 Is there a simple way to convert open and close tag into self-close tag in javascript?
javascript中是否有一种简单的方法可以将打开和关闭标签转换为自关闭标签?
Example:例子:
<td style=""></td>
=> <td style="" />
<td style=""></td>
=> <td style="" />
Try cheerio xmlMode:试试cheerio xmlMode:
let $ = cheerio.load(`<td style=""></td>`, {xmlMode: true})
console.log($.html())
// <td style=""/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.