Skip to content

Is it possible to replace a tag with its own innerHTML? Insert HTMLNode.children into parent.mutableChildren? #83

@Apocryphon

Description

@Apocryphon

I'm looking to replace a tag with all of its own text and HTML content, similar to unwrap in jQuery. Presumably I could do something like:

NSRange currentNodeRange = NSMakeRange([parentNode indexOfChild:currentNode], currentNode.numberOfChildren);
NSIndexSet *newNodesIndexSet = [NSIndexSet indexSetWithIndexesInRange:currentNodeRange];

[parentNode.mutableChildren insertObjects:currentNode.children atIndexes:newNodesIndexSet];

However, insertObjects:atIndexes: only accepts NSArray<HTMLNode *> *, which forces me to use currentNode.childElementNodes. Because that array cannot contain HTMLTextNode objects, it wipes out any text that might have existed in currentNode. Well, I am able to do the above, but I get an incompatible pointer type warning.

What's the best way to accomplish this? Or since I'm able to do the above, could the warning be fixed?

Edit: looks like I can side step the warning with [currentNode.children array], which extracts an NSArray from the NSOrderedSet. However, it's still strange that by default children/mutableChildren do not contain HTMLTextNode objects but only HTMLNode.

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