From 9a3a8523419efa46ed46c3044a5078e34928a7ed Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 14 Feb 2016 18:37:42 +0000 Subject: Convert note references and notes to HTML Currently missing the back link --- .../mammoth/tests/DocumentConverterTests.java | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 17bcdf1..f5b30b2 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -35,7 +35,7 @@ public class DocumentConverterTests { @Test public void multipleParagraphsInDocumentAreConvertedToMultipleParagraphs() { assertThat( - documentConverter().convertToHtml(new Document(list( + convertToHtml(new Document(list( make(a(PARAGRAPH, with(CHILDREN, list(runWithText("Hello"))))), make(a(PARAGRAPH, with(CHILDREN, list(runWithText("there")))))), Notes.EMPTY)), @@ -141,6 +141,27 @@ public class DocumentConverterTests { deepEquals(list(Html.element("a", map("id", "doc-42-start"))))); } + @Test + public void noteReferencesAreConvertedToLinksToReferenceBodyAfterMainBody() { + Document document = new Document( + list(make(a(PARAGRAPH, with(CHILDREN, list( + runWithText("Knock knock"), + make(a(RUN, with(CHILDREN, list(new NoteReference(NoteType.FOOTNOTE, "4")))))))))), + new Notes(list(new Note(NoteType.FOOTNOTE, "4", list(paragraphWithText("Who's there?")))))); + + assertThat( + convertToHtml(document), + deepEquals(list( + Html.element("p", list( + Html.text("Knock knock"), + Html.element("sup", list( + Html.element("a", map("href", "#doc-42-footnote-4", "id", "doc-42-footnote-ref-4"), list(Html.text("[1]"))))))), + Html.element("ol", list( + Html.element("li", map("id", "doc-42-footnote-4"), list( + Html.element("p", list( + Html.text("Who's there?")))))))))); + } + @Test public void imagesAreConvertedToImageTagsWithDataUriByDefault() { Image image = new Image( @@ -163,11 +184,11 @@ public class DocumentConverterTests { contains(hasProperty("attributes", hasEntry("alt", "It's a hat")))); } - private List convertToHtml(DocumentElement element) { - return documentConverter().convertToHtml(element); + private List convertToHtml(Document document) { + return DocumentConverter.convertToHtml("doc-42", document); } - private DocumentConverter documentConverter() { - return new DocumentConverter("doc-42"); + private List convertToHtml(DocumentElement element) { + return DocumentConverter.convertToHtml("doc-42", element); } } -- cgit v1.2.3