From 466d4ed5374e3ada2d335bc04463a426be1327b8 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Feb 2016 21:10:30 +0000 Subject: Allow HTML elements to have a choice of tag names --- src/main/java/org/zwobble/mammoth/html/Html.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/zwobble/mammoth/html/Html.java') diff --git a/src/main/java/org/zwobble/mammoth/html/Html.java b/src/main/java/org/zwobble/mammoth/html/Html.java index c0b234b..e1bcef7 100644 --- a/src/main/java/org/zwobble/mammoth/html/Html.java +++ b/src/main/java/org/zwobble/mammoth/html/Html.java @@ -38,11 +38,15 @@ public class Html { } public static HtmlNode element(String tagName, Map attributes, List children) { - return new HtmlElement(tagName, attributes, children, false); + return new HtmlElement(list(tagName), attributes, children, false); } public static HtmlNode collapsibleElement(String tagName) { - return collapsibleElement(tagName, list()); + return collapsibleElement(list(tagName)); + } + + public static HtmlNode collapsibleElement(List tagNames) { + return collapsibleElement(tagNames, map(), list()); } public static HtmlNode collapsibleElement(String tagName, List children) { @@ -50,7 +54,11 @@ public class Html { } public static HtmlNode collapsibleElement(String tagName, Map attributes, List children) { - return new HtmlElement(tagName, attributes, children, true); + return collapsibleElement(list(tagName), attributes, children); + } + + public static HtmlNode collapsibleElement(List tagNames, Map attributes, List children) { + return new HtmlElement(tagNames, attributes, children, true); } public static HtmlNode selfClosingElement(String tagName) { @@ -74,7 +82,7 @@ public class Html { return list(); } else { return list(new HtmlElement( - element.getTagName(), + element.getTagNames(), element.getAttributes(), children, element.isCollapsible())); @@ -124,7 +132,7 @@ public class Html { @Override public HtmlNode visit(HtmlElement element) { return new HtmlElement( - element.getTagName(), + element.getTagNames(), element.getAttributes(), collapse(element.getChildren()), element.isCollapsible()); @@ -165,7 +173,7 @@ public class Html { } private static boolean isMatch(HtmlElement first, HtmlElement second) { - return first.getTagName().equals(second.getTagName()) && + return second.getTagNames().contains(first.getTagName()) && first.getAttributes().equals(second.getAttributes()); } } -- cgit v1.2.3