1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package org.zwobble.mammoth.html;
import java.util.List;
import java.util.Map;
import static org.zwobble.mammoth.util.MammothLists.list;
import static org.zwobble.mammoth.util.MammothMaps.map;
public class Html {
public static String write(List<HtmlNode> nodes) {
StringBuilder builder = new StringBuilder();
nodes.forEach(node -> node.write(builder));
return builder.toString();
}
public static HtmlNode text(String value) {
return new HtmlTextNode(value);
}
public static HtmlNode element(String tagName) {
return element(tagName, list());
}
public static HtmlNode element(String tagName, Map<String, String> attributes) {
return element(tagName, attributes, list());
}
public static HtmlNode element(String tagName, List<HtmlNode> children) {
return element(tagName, map(), children);
}
public static HtmlNode element(String tagName, Map<String, String> attributes, List<HtmlNode> children) {
return new HtmlElement(tagName, attributes, children);
}
public static HtmlNode selfClosingElement(String tagName) {
return selfClosingElement(tagName, map());
}
public static HtmlNode selfClosingElement(String tagName, Map<String, String> attributes) {
return new HtmlSelfClosingElement(tagName, attributes);
}
}
|