diff options
Diffstat (limited to 'src/main/java/org')
3 files changed, 23 insertions, 11 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()); } } diff --git a/src/main/java/org/zwobble/mammoth/html/HtmlElement.java b/src/main/java/org/zwobble/mammoth/html/HtmlElement.java index cc81aa2..b6dab22 100644 --- a/src/main/java/org/zwobble/mammoth/html/HtmlElement.java +++ b/src/main/java/org/zwobble/mammoth/html/HtmlElement.java @@ -4,20 +4,24 @@ import java.util.List; import java.util.Map; public class HtmlElement implements HtmlNode { - private final String tagName; + private final List<String> tagNames; private final Map<String, String> attributes; private final List<HtmlNode> children; private final boolean collapsible; - public HtmlElement(String tagName, Map<String, String> attributes, List<HtmlNode> children, boolean collapsible) { - this.tagName = tagName; + public HtmlElement(List<String> tagNames, Map<String, String> attributes, List<HtmlNode> children, boolean collapsible) { + this.tagNames = tagNames; this.attributes = attributes; this.children = children; this.collapsible = collapsible; } + public List<String> getTagNames() { + return tagNames; + } + public String getTagName() { - return tagName; + return tagNames.get(0); } public Map<String, String> getAttributes() { diff --git a/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java b/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java index b34fb50..cfd20a6 100644 --- a/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java +++ b/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java @@ -29,6 +29,6 @@ public class HtmlPathElement { } public List<HtmlNode> wrap(List<HtmlNode> nodes) { - return list(new HtmlElement(tagName, attributes, nodes, isCollapsible)); + return list(new HtmlElement(list(tagName), attributes, nodes, isCollapsible)); } } |
