From 32aee86473c4e0865e9ad181be2b8418cd93c9a0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 20 Feb 2016 15:18:06 +0000 Subject: Move note conversion into nested class --- .../org/zwobble/mammoth/DocumentConverter.java | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/zwobble/mammoth/DocumentConverter.java b/src/main/java/org/zwobble/mammoth/DocumentConverter.java index ac09c8b..d04d012 100644 --- a/src/main/java/org/zwobble/mammoth/DocumentConverter.java +++ b/src/main/java/org/zwobble/mammoth/DocumentConverter.java @@ -22,17 +22,7 @@ import static org.zwobble.mammoth.util.MammothMaps.map; public class DocumentConverter { public static List convertToHtml(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, Document document) { DocumentConverter documentConverter = new DocumentConverter(idPrefix, preserveEmptyParagraphs, styleMap); - List mainBody = documentConverter.convertChildrenToHtml(document); - // TODO: can you have note references inside a note? - List notes = findNotes(document, documentConverter.noteReferences); - if (notes.isEmpty()) { - return mainBody; - } else { - HtmlNode noteNode = Html.element("ol", - ImmutableList.copyOf(Iterables.transform(notes, documentConverter::convertToHtml))); - - return ImmutableList.copyOf(Iterables.concat(mainBody, list(noteNode))); - } + return documentConverter.convertToHtml(document); } private static List findNotes(Document document, Iterable noteReferences) { @@ -57,6 +47,20 @@ public class DocumentConverter { this.styleMap = styleMap; } + private List convertToHtml(Document document) { + List mainBody = convertChildrenToHtml(document); + // TODO: can you have note references inside a note? + List notes = findNotes(document, noteReferences); + if (notes.isEmpty()) { + return mainBody; + } else { + HtmlNode noteNode = Html.element("ol", + ImmutableList.copyOf(Iterables.transform(notes, this::convertToHtml))); + + return ImmutableList.copyOf(Iterables.concat(mainBody, list(noteNode))); + } + } + private HtmlNode convertToHtml(Note note) { String id = generateNoteHtmlId(note.getNoteType(), note.getId()); String referenceId = generateNoteRefHtmlId(note.getNoteType(), note.getId()); -- cgit v1.2.3