Skip to content

a tag nesting breaks everything #211

@lehtu

Description

@lehtu

It seems that this lib cannot handle a tag nesting. If there is an a tag inside another one and there are other tag openings in between, the parser will force close all tags between two a tag openings.

This is of course not valid HTML, although it's semantically valid, but still I thought that parser would do what it promises. As a developer I want to be able to parse HTML no matter who has produced it, especially if it's semantically alright.

Is there any workarounds for this?

example1:

import { parse } from 'node-html-parser';

const root = parse(`
  <a>
    <table>
      <tr>
        <td>
          <a href="https://github.com">link to github</a>
        </td>
      </tr>
    </table>
  </a>
`);

console.log(root.toString());
// outputs
<a>
<table>
  <tr>
    <td>
      </td></tr></table></a><a href="https://github.com">link to github</a>

example2:

import { parse } from 'node-html-parser';

const root = parse(`
    <a>
      <a href="https://github.com">link to github</a>
    </a>
`);

console.log(root.toString());
//outputs:
    <a>
      </a><a href="https://github.com">link to github</a>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions