Skip to content

Conversation

@remysucre
Copy link

This PR adds text content as children nodes to the parent node, e.g. <p>Hello<br>World</p> will parse to a p node with 3 children: a text node containing Hello, the br node, and a text node containing World. A text node has nil as its tagname (because it has no tagname), but we can discuss this choice. The added and modified tests give some sense of the new behavior.

This is similar to #49 with a few differences:

  1. Text nodes have nil as tagname which will never create collisions
  2. This PR supports multiple text nodes intermixed with nested tags, like <p>Hello<br>World</p>

@remysucre
Copy link
Author

6e41361 uses _text instead of nil as the tagname for text nodes, so that they can be selected with selectors (but may create conflicts if there are also <_text> tags).
For clarity I also renamed the existing _text field to _rawtext and gettext() to getrawtext(), but that is not necessary because text nodes are added as elements, not a field.

@msva
Copy link
Owner

msva commented Dec 10, 2025

Well, unfortunatelly, I have almost no time to properly test that all, but at quick look, it looks very good.

Although, it would be nice to add some warning to readme about (potentially) breaking change in API.

If I'll be lucky, I'll try to merge this at weekend (but can't promise)

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

Successfully merging this pull request may close these issues.

2 participants