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

Improve parsing of HTML anchor content #54

Merged
merged 2 commits into from
May 16, 2022

Conversation

sorcio
Copy link
Contributor

@sorcio sorcio commented May 7, 2022

This attempts to address #53.

  1. Fixes case 1 by skipping child elements of any link anchor
  2. Fixes case 2 by normalizing whitespace (at least in the easy case) of anchor textContent

I'm not sure if this has any significant performance impact that should be evaluated. I tried to paste some large content and at least I didn't notice it being any slower than before. Calling a node filter on every element in the tree could be expensive, but maybe not too much?

This does not address the <br> case. I guess the only way to deal with it would be to traverse the children of the anchor and collect the text, but even that would probably not cover all the cases. And I suspect it might be too expensive if somehow it happens that the tree under the anchor element is very complex.

I also realized that using innerText instead of textContent doesn't work here (while normally it makes a difference), because when the element is not being rendered the DOM doesn't care about the semantics of <br>.

Please just take this as a suggestion. I mostly don't understand what I'm doing but wanted to give this a try anyway.

@sorcio sorcio requested a review from a team as a code owner May 7, 2022 00:36
@sorcio sorcio requested a review from koddsson May 7, 2022 00:36
@manuelpuyol
Copy link
Contributor

Thanks for working on it @sorcio !

@manuelpuyol manuelpuyol merged commit feca08c into github:main May 16, 2022
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