Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly trimming whitespaces for text nodes #22

Closed
bennyboer opened this issue Jul 18, 2022 · 1 comment
Closed

Incorrectly trimming whitespaces for text nodes #22

bennyboer opened this issue Jul 18, 2022 · 1 comment

Comments

@bennyboer
Copy link
Contributor

Hi there again!

While testing a little bit I noticed that the parser was incorrectly trimming text nodes.

Example

<p> Hello para<b>gra</b>ph! </p>
<p> Hello para <b>gra</b> ph! </p>

for this example I would expect to get the following output:

{
  "treeType": "documentFragment",
  "children": [
    {
      "name": "p",
      "variant": "normal",
      "children": [
        " Hello para",
        {
          "name": "b",
          "variant": "normal",
          "children": [
            "gra"
          ]
        },
        "ph! "
      ]
    },
    {
      "name": "p",
      "variant": "normal",
      "children": [
        " Hello para ",
        {
          "name": "b",
          "variant": "normal",
          "children": [
            "gra"
          ]
        },
        " ph! "
      ]
    }
  ]
}

Notice the white spaces in the second paragraph nodes children.

With the current version of the HTML parser I get the following instead:

{
  "treeType": "documentFragment",
  "children": [
    {
      "name": "p",
      "variant": "normal",
      "children": [
        "Hello para",
        {
          "name": "b",
          "variant": "normal",
          "children": [
            "gra"
          ]
        },
        "ph!"
      ]
    },
    {
      "name": "p",
      "variant": "normal",
      "children": [
        "Hello para",
        {
          "name": "b",
          "variant": "normal",
          "children": [
            "gra"
          ]
        },
        "ph!"
      ]
    }
  ]
}

As you can see there is no difference between the two paragraphs with the current version of HTML Parser (0.6.3).

I will provide a PR with a possible fix ASAP! 😄

@mathiversen
Copy link
Owner

Thanks Benny! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants