DOCX4J version: 3.0.1
Modify JAR Package: docx4j-importxhtml
The MAVEN configuration is:
Specific code location: \org\docx4j\convert\in\xhtml\xhtmlimporterimpl.java in Processinlineboxcontent method
Before code modification:
After the code has been modified:
private void Processinlineboxcontent (Inlinebox inlinebox, styleable s,map<string, cssvalue> cssMap) {if ( Inlinebox.gettextnode () ==null) {if (S.getelement (). Getnodename (). Equals ("BR")) { R run = context.getwmlobjectfactory (). creater ();//Getlistforrun (). GetContent (). Add (ru n); Run.getcontent (). Add (Context.getwmlobjectfactory (). CREATEBR ()); Element ele = S.getelement (); if (null! = ele) {Attr attrnode = Ele.getattributenode ("style"); if (attrnode! = null && attrnode.getvalue (). Contains ("Page-break-after:always")) {br BR = Context.getwmlo Bjectfactory (). CREATEBR (); P p = context.getwmlobjectfactory (). Createp (); Create object for r r r = Context.getwmlobjectfactory (). creater (); P.getcontent (). Add (R); Br.settype (Stbrtype.page); R.getcontent (). Add (BR); This.contentContextStack.peek (). GetContent (). Add (P); }//Wordmlpackage.getmaindocumentpart (). AddObject (P); }} else {Log.debug ("Inlinebox have no textnode, so skipping"); Todo.. A span in a span or a? Need to traverse? }} else {Log.debug (Inlinebox.gettextnode (). Gettextcontent ()); Don ' t use. GetText () String thetext = Inlinebox.gettextnode (). Gettextcontent (); Log.debug ("Processing" + thetext); Parastillempty = false; String CssClass = Getclassattribute (S.getelement ()); if (cssclass!=null) {Cssclass=cssclass.trim (); } addrun (CssClass, Cssmap, thetext); else {////Get it from the parent element eg p// Map Cssmap = StyleREference.getcascadedpropertiesmap (e);//RUN.SETRPR (// Addrunproperties (Cssmap)); // } }}
docx4j Change the BR label to soft return when HTML is turned into Word