From 8dd12c1ca7703a085b57fe4c5c35ef6e19d92134 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 24 Feb 2016 09:04:14 +0000 Subject: Allow style maps to be added --- .../mammoth/tests/DocumentConverterTests.java | 2 +- .../org/zwobble/mammoth/tests/MammothTests.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 4c40800..df60d06 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -312,7 +312,7 @@ public class DocumentConverterTests { private Result> convertToHtmlResult(DocumentElement element, StyleMap styleMap) { DocumentToHtmlOptions options = DocumentToHtmlOptions.DEFAULT .idPrefix("doc-42-") - .styleMap(styleMap); + .addStyleMap(styleMap); return DocumentConverter.convertToHtml(element, options); } } diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index 6e5794a..288c6a2 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -167,6 +167,27 @@ public class MammothTests { deepEquals(success("

Datum plane

"))); } + @Test + public void canUseCustomStyleMap() throws IOException { + assertThat( + convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em")), + deepEquals(success("

The Sunset Tree

"))); + } + + @Test + public void mostRecentlyAddedStyleMapTakesPrecedence() throws IOException { + assertThat( + convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em").addStyleMap("u => strong")), + deepEquals(success("

The Sunset Tree

"))); + } + + @Test + public void rulesFromPreviouslyAddedStyleMapsStillTakeEffectIfNotOverriden() throws IOException { + assertThat( + convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em").addStyleMap("s => del")), + deepEquals(success("

The Sunset Tree

"))); + } + @Test public void canExtractRawText() throws IOException { assertThat( -- cgit v1.2.3