Suggestions on how build an HTML Diff tool?

前端 未结 16 1755
灰色年华
灰色年华 2021-02-02 02:00

In this post I asked if there were any tools that compare the structure (not actual content) of 2 HTML pages. I ask because I receive HTML templates from our designers, and freq

16条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 02:22

    @Mike - that would compare everything, including the content of the page, which isn't want the original poster wanted.

    Assuming that you have access to the browser's DOM (by writing a Firefox/IE plugin or whatever), I would probably put all of the HTML elements into a tree, then compare the two trees. If the tag name is different, then the node is different. You might want to stop enumerating at a certain point (you probably don't care about span, bold, italic, etc. - maybe only worry about divs?), since some tags are really the content, rather than the structure, of the page.

提交回复
热议问题