Source:
private static Node processFontTag(Node node, Document doc, NamedNodeMap attributes) { Node localNode = node; Element elem = null; if (node instanceof Element) { elem = (Element) node; } else { return localNode; } String URI = localNode.getNamespaceURI(); URI = (URI == null) ? "" : URI; localNode = doc.renameNode(localNode, URI, "span"); String style = ""; ArrayList<Attr> theAttributesToRemove = new ArrayList<Attr>(); String theSizeString = ""; for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); String attributeName = attribute.getLocalName(); String attributeValue = attribute.getNodeValue(); if (!attributeValue.endsWith(";")) { attributeValue += ";"; } if (attributeName.equalsIgnoreCase("face")) { style = String.format("%s font-family: %s", style, attributeValue); } else if (attributeName.equalsIgnoreCase("size") && theSizeString.equals("")) { String numericSize = attributeValue.trim(); numericSize = numericSize.substring(0, numericSize.length() - 1); int theSize = Integer.valueOf(numericSize); theSizeString = getFontSize(theSize, true); } else if (attributeName.equalsIgnoreCase("color")) { style = String.format("%s color: %s", style, attributeValue); } else if (attributeName.equalsIgnoreCase("style")) { int size = attributeValue.indexOf("font-size:"); if (size != -1) { size += "font-size:".length(); theSizeString = getFontSize(attributeValue.substring(size)); } } if (attribute instanceof Attr) { theAttributesToRemove.add((Attr) attribute); } } for (Attr attr : theAttributesToRemove) { elem.removeAttributeNode(attr); } if (Strings.isValid(theSizeString)) { style = String.format("%s font-size: %s", style, theSizeString); } elem.setAttribute("style", style); return localNode; }

Target:
private Node processFontTag(Node node, Document doc, NamedNodeMap attributes) { Element elem = null; if (!(node instanceof Element)) { return node; } String URI = Strings.nullToEmpty(node.getNamespaceURI()); node = doc.renameNode(node, URI, "span"); elem = (Element) node; String style = ""; ArrayList<Attr> theAttributesToRemove = new ArrayList<Attr>(); String theSizeString = ""; for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); String attributeName = attribute.getLocalName(); String attributeValue = attribute.getNodeValue(); if (!attributeValue.endsWith(";")) { attributeValue += ";"; } if (attributeName.equalsIgnoreCase("face")) { style = String.format("%s font-family: %s", style, attributeValue); } else if (attributeName.equalsIgnoreCase("size") && theSizeString.equals("")) { String numericSize = attributeValue.trim(); numericSize = numericSize.substring(0, numericSize.length() - 1); int theSize = Integer.valueOf(numericSize); theSizeString = getFontSize(theSize, true); } else if (attributeName.equalsIgnoreCase("color")) { style = String.format("%s color: %s", style, attributeValue); } else if (attributeName.equalsIgnoreCase("style")) { int size = attributeValue.indexOf("font-size:"); if (size != -1) { size += "font-size:".length(); theSizeString = getFontSize(attributeValue.substring(size)); } } if (attribute instanceof Attr) { theAttributesToRemove.add((Attr) attribute); } } for (Attr attr : theAttributesToRemove) { elem.removeAttributeNode(attr); } if (!Strings.isNullOrEmpty(theSizeString)) { style = String.format("%s font-size: %s", style, theSizeString); } elem.setAttribute("style", style); return node; }