mirror of https://github.com/apache/poi.git
more compact HTML in Word-to-HTML converter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1149035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c7ae9b50db
commit
87f42602fe
|
@ -45,6 +45,8 @@ import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH;
|
import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH;
|
||||||
|
@ -523,6 +525,32 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||||
htmlDocumentFacade.getOrCreateCssClass(
|
htmlDocumentFacade.getOrCreateCssClass(
|
||||||
pElement.getTagName(), "p", style.toString() ) );
|
pElement.getTagName(), "p", style.toString() ) );
|
||||||
|
|
||||||
|
{
|
||||||
|
// compact spans
|
||||||
|
NodeList childNodes = pElement.getChildNodes();
|
||||||
|
for ( int i = 0; i < childNodes.getLength() - 1; i++ )
|
||||||
|
{
|
||||||
|
Node child1 = childNodes.item( i );
|
||||||
|
Node child2 = childNodes.item( i + 1 );
|
||||||
|
if ( child1.getNodeType() != Node.ELEMENT_NODE
|
||||||
|
|| child2.getNodeType() != Node.ELEMENT_NODE
|
||||||
|
|| !WordToHtmlUtils.equals( "span",
|
||||||
|
( (Element) child1 ).getTagName() )
|
||||||
|
|| !WordToHtmlUtils.equals( "span",
|
||||||
|
( (Element) child2 ).getTagName() )
|
||||||
|
|| !WordToHtmlUtils.equals(
|
||||||
|
( (Element) child1 ).getAttribute( "class" ),
|
||||||
|
( (Element) child2 ).getAttribute( "class" ) ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// merge
|
||||||
|
while ( child2.getChildNodes().getLength() > 0 )
|
||||||
|
child1.appendChild( child2.getFirstChild() );
|
||||||
|
child2.getParentNode().removeChild( child2 );
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue