aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-14 11:27:21 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-14 11:27:21 +0000
commit7fb58782e670a13ac7389e43ff0bacbce19f9d05 (patch)
tree4af2b8b58797fa44ccc3e9ca33e06cc336896d67
parent7eb51f99ed46e35b42e5bdd4e73dc55aa989b183 (diff)
Wrap subscript runs in <sub>
-rw-r--r--src/main/java/org/zwobble/mammoth/DocumentConverter.java3
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java8
2 files changed, 11 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/DocumentConverter.java b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
index 2c2d7cd..be2f68e 100644
--- a/src/main/java/org/zwobble/mammoth/DocumentConverter.java
+++ b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
@@ -38,6 +38,9 @@ public class DocumentConverter {
if (run.isStrikethrough()) {
nodes = list(Html.element("s", nodes));
}
+ if (run.getVerticalAlignment() == VerticalAlignment.SUBSCRIPT) {
+ nodes = list(Html.element("sub", nodes));
+ }
if (run.getVerticalAlignment() == VerticalAlignment.SUPERSCRIPT) {
nodes = list(Html.element("sup", nodes));
}
diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
index 8024291..ff12f5d 100644
--- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
@@ -12,6 +12,7 @@ import java.util.List;
import static com.natpryce.makeiteasy.MakeItEasy.*;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.zwobble.mammoth.documents.VerticalAlignment.SUBSCRIPT;
import static org.zwobble.mammoth.documents.VerticalAlignment.SUPERSCRIPT;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*;
@@ -74,6 +75,13 @@ public class DocumentConverterTests {
deepEquals(list(Html.element("sup", list(Html.text("Hello"))))));
}
+ @Test
+ public void subscriptRunsAreWrappedInSubscriptTags() {
+ assertThat(
+ convertToHtml(make(a(RUN, with(VERTICAL_ALIGNMENT, SUBSCRIPT), with(CHILDREN, list(new Text("Hello")))))),
+ deepEquals(list(Html.element("sub", list(Html.text("Hello"))))));
+ }
+
private List<HtmlNode> convertToHtml(DocumentElement element) {
return DocumentConverter.convertToHtml(element);