aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/HtmlPath.java13
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/StyleMap.java4
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java14
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java2
4 files changed, 12 insertions, 21 deletions
diff --git a/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java b/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
index b03d0b6..ffad58c 100644
--- a/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
+++ b/src/main/java/org/zwobble/mammoth/styles/HtmlPath.java
@@ -6,19 +6,22 @@ import org.zwobble.mammoth.html.HtmlNode;
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 HtmlPath {
- public static HtmlPathElement element(String tagName) {
+ public static final HtmlPath EMPTY = new HtmlPath(list());
+
+ public static HtmlPath element(String tagName) {
return element(tagName, map());
}
- public static HtmlPathElement element(String tagName, Map<String, String> attributes) {
- return new HtmlPathElement(tagName, attributes, false);
+ public static HtmlPath element(String tagName, Map<String, String> attributes) {
+ return new HtmlPath(list(new HtmlPathElement(tagName, attributes, false)));
}
- public static HtmlPathElement collapsibleElement(String tagName) {
- return new HtmlPathElement(tagName, map(), true);
+ public static HtmlPath collapsibleElement(String tagName) {
+ return new HtmlPath(list(new HtmlPathElement(tagName, map(), true)));
}
private final List<HtmlPathElement> elements;
diff --git a/src/main/java/org/zwobble/mammoth/styles/StyleMap.java b/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
index 383554f..237a20e 100644
--- a/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
+++ b/src/main/java/org/zwobble/mammoth/styles/StyleMap.java
@@ -5,8 +5,6 @@ import org.zwobble.mammoth.documents.Paragraph;
import java.util.Map;
import java.util.Optional;
-import static org.zwobble.mammoth.util.MammothLists.list;
-
public class StyleMap {
public static StyleMapBuilder builder() {
return new StyleMapBuilder();
@@ -35,6 +33,6 @@ public class StyleMap {
public HtmlPath getParagraphStyleMapping(Paragraph paragraph) {
return paragraph.getStyle()
.flatMap(style -> Optional.ofNullable(paragraphStyles.get(style.getStyleId())))
- .orElse(new HtmlPath(list(HtmlPath.element("p"))));
+ .orElse(HtmlPath.element("p"));
}
}
diff --git a/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java b/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java
index c815e1b..98ae351 100644
--- a/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java
+++ b/src/main/java/org/zwobble/mammoth/styles/StyleMapBuilder.java
@@ -2,20 +2,14 @@ package org.zwobble.mammoth.styles;
import com.google.common.collect.ImmutableMap;
-import static org.zwobble.mammoth.util.MammothLists.list;
-
public class StyleMapBuilder {
private HtmlPath underline;
private HtmlPath strikethrough;
private final ImmutableMap.Builder<String, HtmlPath> paragraphStyles = ImmutableMap.builder();
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)));
+ this.underline = HtmlPath.EMPTY;
+ this.strikethrough = HtmlPath.collapsibleElement("s");
}
public StyleMapBuilder underline(HtmlPath path) {
@@ -23,10 +17,6 @@ public class StyleMapBuilder {
return this;
}
- public StyleMapBuilder strikethrough(HtmlPathElement element) {
- return strikethrough(new HtmlPath(list(element)));
- }
-
public StyleMapBuilder strikethrough(HtmlPath path) {
this.strikethrough = path;
return this;
diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
index 8e76619..771431f 100644
--- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
@@ -56,7 +56,7 @@ public class DocumentConverterTests {
assertThat(
convertToHtml(
make(a(PARAGRAPH, with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty()))))),
- StyleMap.builder().mapParagraph("TipsParagraph", new HtmlPath(list(HtmlPath.element("p", map("class", "tip"))))).build()),
+ StyleMap.builder().mapParagraph("TipsParagraph", HtmlPath.element("p", map("class", "tip"))).build()),
deepEquals(list(Html.element("p", map("class", "tip")))));
}