Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ public void head(Node node, int depth) {

public void tail(Node node, int depth) {
// make sure there is a space between block tags and immediately
// following text nodes <div>One</div>Two should be "One Two".
// following siblings <div>One</div><a>Two</a> should be "One Two".
if (node instanceof Element) {
Element element = (Element) node;
if (element == excluded) {
excluded = null;
}
if (element.isBlock()
&& (node.nextSibling() instanceof TextNode)
&& node.nextSibling() != null
&& !lastCharIsWhitespace(accum)) {
accum.append(' ');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ void testExclusionCase() throws IOException {
assertEquals("the content of the page", text);
}

@Test
void testBlockFollowedByInlineElement() {
Config conf = new Config();
JSoupTextExtractor extractor = new JSoupTextExtractor(conf);
// block element followed by an inline anchor — see #1925
String content =
"<html><body><div>"
+ "<h3>Contact</h3>"
+ "<a href=\"mailto:info@example.com\">info@example.com</a>"
+ "</div></body></html>";
Document jsoupDoc = Parser.htmlParser().parseInput(content, "http://example.com");
String text = extractor.text(jsoupDoc.body());
assertEquals("Contact info@example.com", text);
}

@Test
void testBlockFollowedByInlineSpan() {
Config conf = new Config();
JSoupTextExtractor extractor = new JSoupTextExtractor(conf);
String content =
"<html><body><div>"
+ "<div>Phone</div>"
+ "<span>555-0100</span>"
+ "</div></body></html>";
Document jsoupDoc = Parser.htmlParser().parseInput(content, "http://example.com");
String text = extractor.text(jsoupDoc.body());
assertEquals("Phone 555-0100", text);
}

@Test
void testTrimContent() throws IOException {
Config conf = new Config();
Expand Down