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

org.jsoup.nodes.Element.wholeText() not correctly translating <br> ? #1437

Closed
JupiterRider opened this issue Oct 23, 2020 · 2 comments
Closed
Labels
Milestone

Comments

@JupiterRider
Copy link

JupiterRider commented Oct 23, 2020

String s = Jsoup.parse("Hello<br>World").wholeText();
System.out.println(s);

prints HelloWorld.

But shouldn't it be
Hello
World ?

There is no line separator.

firefox

ide

@suarez12138
Copy link
Contributor

Maybe it can be solved by adding detection of special tags like <br> and convert them manually in wholeText().

public void head(Node node, int depth) {
                if (node instanceof TextNode) {
                    TextNode textNode = (TextNode) node;
                    accum.append(textNode.getWholeText());
                }else if (node.nodeName().equals("br")){
                    accum.append("\n");
                }
            }

But whether there is a need to do it? And deal with more special tags like <hr> or just <br> ?

suarez12138 added a commit to suarez12138/jsoup that referenced this issue Apr 16, 2021
jhy added a commit that referenced this issue Jan 2, 2022
@jhy jhy added this to the 1.15.1 milestone Jan 2, 2022
@jhy jhy added the fixed label Jan 2, 2022
@jhy
Copy link
Owner

jhy commented Jan 2, 2022

Thanks this was fixed in #1636

@jhy jhy closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants