Skip to content

Commit

Permalink
Fixed converting alt chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Desire456 committed Jul 1, 2021
1 parent 4f1f7b3 commit 70a6c7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected void updateTableOfContents() {
} catch (Docx4JException e) {
throw new RuntimeException("Unable to get document content", e);
}
Body body = wmlDocumentEl.getBody();
Body body = wmlDocumentEl.getBody();

TocFinder finder = new TocFinder();
new TraversalUtil(body.getContent(), finder);
Expand Down Expand Up @@ -251,25 +251,24 @@ public void convertAltChunks() throws Docx4JException {
Object chunkParent = locatedChunk.getAltChunk().getParent();
R run = (R) chunkParent;//always should be R
P paragraph = (P) run.getParent();
ContentAccessor paragraphParent = (ContentAccessor) paragraph.getParent();

if (results.size() == 1 && results.get(0) instanceof P) {
P resultP = (P)results.get(0);
paragraph.getContent().addAll(resultP.getContent());
if (paragraphParent instanceof ArrayListWml) {
ArrayListWml parent = (ArrayListWml) paragraph.getParent();
parent.addAll(parent.indexOf(paragraph), results);
if (results.get(0) instanceof P) {
P resultParagraph = (P) results.get(0);
resultParagraph.setPPr(paragraph.getPPr());
}
parent.remove(paragraph);
} else {
if (paragraph.getParent() instanceof ArrayListWml) {
ArrayListWml parent = (ArrayListWml) paragraph.getParent();
parent.addAll(parent.indexOf(paragraph), results);
if (results.get(0) instanceof P) {
P resultParagraph = (P) results.get(0);
resultParagraph.setPPr(paragraph.getPPr());
}
parent.remove(paragraph);
} else {
for (Object result : results) {
if (result instanceof P) {
P resultParagraph = (P) result;
paragraph.getContent().addAll(resultParagraph.getContent());
}
List<Object> destinationContent = paragraphParent.getContent();
int indexToAdd = destinationContent.indexOf(paragraph);
destinationContent.remove(indexToAdd);
for (Object result : results) {
if (result instanceof P) {
P resultParagraph = (P) result;
destinationContent.add(indexToAdd++, resultParagraph);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void processFontColor(org.jsoup.nodes.Document document) {
Elements elements = document.getElementsByTag("font");
for (Element element : elements) {
String color = element.attr("color");
if (color != null) {
if (StringUtils.isNotEmpty(color)) {
String style = StringUtils.trim(element.attr("style"));
if (style != null) {
if (StringUtils.endsWith(style, ";")) {
Expand Down

0 comments on commit 70a6c7e

Please sign in to comment.