diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index fa541d5661..7b83891985 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -86,6 +86,36 @@ public Element(Tag tag, @Nullable String baseUri) { this(tag, baseUri, null); } + private Element() { + this("-"); + } + + /** + * Parse HTML String into an Element + *
+ * Use examples: + *
Element e = Element.parse("");
Element e = Element.parse("Some stuffSecond part");
Element e = Element.parse("- item1
- item2
");
P3
"); + Element p4 = Element.parse("P4
"); div.insertChildren(1, p3); div.insertChildren(3, p4); Elements els2 = div.children(); @@ -1839,8 +1839,8 @@ public void doesntDeleteZWJWhenNormalizingText() { public void testReparentSeperateNodes() { String html = "One
Two"; Document doc = Jsoup.parse(html); - Element new1 = new Element("p").text("Three"); - Element new2 = new Element("p").text("Four"); + Element new1 = Element.parse("
Three
"); + Element new2 = Element.parse("Four
"); doc.body().insertChildren(-1, new1, new2); assertEquals("One
Two
Three
Four
", TextUtil.stripNewlines(doc.body().html())); @@ -1863,14 +1863,14 @@ public void testNotActuallyAReparent() { String html = "One
"); + Element new2 = Element.parse("Two
"); div.addChildren(new1, new2); assertEquals("One
Two
Three
"); Element wrap = new Element("nav"); wrap.addChildren(0, new1, new3); @@ -2099,4 +2099,21 @@ public void childNodesAccessorDoesNotVivify() { p.removeAttr("foo"); assertEquals(0, p.attributesSize()); } + + @Test void parseFromHtmlOneElementSuccess() { + Element e = Element.parse("