diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-21 21:10:30 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-21 21:10:30 +0000 |
| commit | 466d4ed5374e3ada2d335bc04463a426be1327b8 (patch) | |
| tree | d44604afbd6b1742dfb12abfd32b6861171ab830 /src/main/java/org/zwobble/mammoth/html/Html.java | |
| parent | c0d800cb5f6407e6ba8b013840a6b8df48def2eb (diff) | |
Allow HTML elements to have a choice of tag names
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/html/Html.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/html/Html.java | 20 |
1 files changed, 14 insertions, 6 deletions
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<String, String> attributes, List<HtmlNode> 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<String> tagNames) { + return collapsibleElement(tagNames, map(), list()); } public static HtmlNode collapsibleElement(String tagName, List<HtmlNode> children) { @@ -50,7 +54,11 @@ public class Html { } public static HtmlNode collapsibleElement(String tagName, Map<String, String> attributes, List<HtmlNode> children) { - return new HtmlElement(tagName, attributes, children, true); + return collapsibleElement(list(tagName), attributes, children); + } + + public static HtmlNode collapsibleElement(List<String> tagNames, Map<String, String> attributes, List<HtmlNode> 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()); } } |
