aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/styles
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-20 14:20:40 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-20 14:20:40 +0000
commitbba2f4d95240ea3569e253609e95cc94c5c8ef13 (patch)
tree1a510988da0f17f4a3222a0b2f62de4b2f1cf641 /src/main/java/org/zwobble/mammoth/styles
parenta3eb5f0c3ee50afafc517c4a7e36501539489178 (diff)
Add strikethrough to style map
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/styles')
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/HtmlPath.java18
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java16
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/StyleMap.java16
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java35
4 files changed, 76 insertions, 9 deletions
diff --git a/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java b/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
index 27e63c4..99bdf55 100644
--- a/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
+++ b/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
@@ -1,15 +1,29 @@
package org.zwobble.mammoth.styles;
+import com.google.common.collect.Lists;
+import org.zwobble.mammoth.html.HtmlNode;
+
import java.util.List;
public class HtmlPath {
+ public static HtmlPathElement element(String tagName) {
+ return new HtmlPathElement(tagName, false);
+ }
+
+ public static HtmlPathElement collapsibleElement(String tagName) {
+ return new HtmlPathElement(tagName, true);
+ }
+
private final List<HtmlPathElement> elements;
public HtmlPath(List<HtmlPathElement> elements) {
this.elements = elements;
}
- public List<HtmlPathElement> getElements() {
- return elements;
+ public List<HtmlNode> wrap(List<HtmlNode> nodes) {
+ for (HtmlPathElement element : Lists.reverse(elements)) {
+ nodes = element.wrap(nodes);
+ }
+ return nodes;
}
}
diff --git a/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java b/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java
index 0166c7a..d2d9363 100644
--- a/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java
+++ b/src/main/java/org/zwobble/mammoth/styles/HtmlPathElement.java
@@ -1,13 +1,23 @@
package org.zwobble.mammoth.styles;
+import org.zwobble.mammoth.html.HtmlElement;
+import org.zwobble.mammoth.html.HtmlNode;
+
+import java.util.List;
+
+import static org.zwobble.mammoth.util.MammothLists.list;
+import static org.zwobble.mammoth.util.MammothMaps.map;
+
public class HtmlPathElement {
private final String tagName;
+ private final boolean isCollapsible;
- public HtmlPathElement(String tagName) {
+ public HtmlPathElement(String tagName, boolean isCollapsible) {
this.tagName = tagName;
+ this.isCollapsible = isCollapsible;
}
- public String getTagName() {
- return tagName;
+ public List<HtmlNode> wrap(List<HtmlNode> nodes) {
+ return list(new HtmlElement(tagName, map(), nodes, isCollapsible));
}
}
diff --git a/src/main/java/org/zwobble/mammoth/styles/StyleMap.java b/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
index bdc8483..1db5c65 100644
--- a/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
+++ b/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
@@ -1,17 +1,25 @@
package org.zwobble.mammoth.styles;
-import static org.zwobble.mammoth.util.MammothLists.list;
-
public class StyleMap {
- public static final StyleMap EMPTY = new StyleMap(new HtmlPath(list()));
+ public static StyleMapBuilder builder() {
+ return new StyleMapBuilder();
+ }
+
+ public static final StyleMap EMPTY = new StyleMapBuilder().build();
private final HtmlPath underline;
+ private final HtmlPath strikethrough;
- public StyleMap(HtmlPath underline) {
+ public StyleMap(HtmlPath underline, HtmlPath strikethrough) {
this.underline = underline;
+ this.strikethrough = strikethrough;
}
public HtmlPath getUnderline() {
return underline;
}
+
+ public HtmlPath getStrikethrough() {
+ return strikethrough;
+ }
}
diff --git a/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java b/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java
new file mode 100644
index 0000000..93a2c8c
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java
@@ -0,0 +1,35 @@
+package org.zwobble.mammoth.styles;
+
+import static org.zwobble.mammoth.util.MammothLists.list;
+
+public class StyleMapBuilder {
+ private HtmlPath underline;
+ private HtmlPath strikethrough;
+
+ public StyleMapBuilder() {
+ this.underline = new HtmlPath(list());
+ this.strikethrough = new HtmlPath(list(HtmlPath.collapsibleElement("s")));
+ }
+
+ public StyleMapBuilder underline(HtmlPathElement element) {
+ return underline(new HtmlPath(list(element)));
+ }
+
+ public StyleMapBuilder underline(HtmlPath path) {
+ this.underline = path;
+ return this;
+ }
+
+ public StyleMapBuilder strikethrough(HtmlPathElement element) {
+ return strikethrough(new HtmlPath(list(element)));
+ }
+
+ public StyleMapBuilder strikethrough(HtmlPath path) {
+ this.strikethrough = path;
+ return this;
+ }
+
+ public StyleMap build() {
+ return new StyleMap(underline, strikethrough);
+ }
+}