From a8e110a01261cd6337fa1c4af1a699162d2e9131 Mon Sep 17 00:00:00 2001 From: Jason Harrop Date: Tue, 12 Jan 2021 12:30:56 +1100 Subject: [PATCH] Handle br (soft return). Ignore pseudo-elements, so we don't get 2 of them. --- .../convert/in/xhtml/XHTMLImporterImpl.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java b/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java index 3d4be5b..474d8e0 100644 --- a/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java +++ b/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java @@ -1842,6 +1842,11 @@ private float dotsToTwip(float dots) { private void processInlineBox( InlineBox inlineBox) { + if (inlineBox.getPseudoElementOrClass()!=null) { + log.debug("Ignoring Pseudo"); + return; + } + // Doesn't extend box Styleable s = inlineBox; @@ -2080,8 +2085,14 @@ private void processInlineBoxContent(InlineBox inlineBox, Styleable s, CTMarkupRange markupRangeForID = bookmarkHelper.anchorToBookmark(inlineBox.getElement(), bookmarkNamePrefix, getCurrentParagraph(false), this.contentContextStack.peek()); - - if (inlineBox.getText()==null) { + if (s!=null && s.getElement()!=null && s.getElement().getNodeName().equals("br") ) { + + R run = Context.getWmlObjectFactory().createR(); + getListForRun().getContent().add(run); + run.getContent().add(Context.getWmlObjectFactory().createBr()); + + } else if (inlineBox.getText()==null) { + // Doesn't happen anymore, now we're using openhtmltopdf? if (s == null) { log.debug("Null Styleable" ); @@ -2089,13 +2100,7 @@ private void processInlineBoxContent(InlineBox inlineBox, Styleable s, log.debug("Null element " ); } else if (s.getElement().getNodeName() == null) { log.debug("Null element nodename " ); - } else if (s.getElement().getNodeName().equals("br") ) { - - R run = Context.getWmlObjectFactory().createR(); - getListForRun().getContent().add(run); - run.getContent().add(Context.getWmlObjectFactory().createBr()); - - } else { + } else { log.debug("InlineBox has no TextNode, so skipping" ); // TODO .. a span in a span or a?