Skip to content

Sub-nodes are coupled with contents() method #231

Description

@lonecrane

contents() method is extremely useful to deal with a node that has text node child.
However, it seems that can't generate correct childnodes in that following case.
Consider

from pyquery import PyQuery as pq

html = '''<span>123<br>...456<br>...789</span>'''
doc = pq(html)
childnodes = doc.contents()
print('sub-node count by contents(): ', childnodes.size())
for childnode in childnodes.items():
    pass
    print(childnode)

It will yield

<p>123</p>
<br/>...456
<p>...456</p>
<br/>...789
<p>...789</p>

We can find that the 2nd sub-node and the 3rd one are coupled, and so are the 4th and the 5th.
I am not sure it is a bug. Can anybody have a look at this?
In addition, why the original text nodes are wrapped with a

tag automatically? It seems a redundant action.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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