| Index: java/org/chromium/distiller/DomUtil.java
|
| diff --git a/java/org/chromium/distiller/DomUtil.java b/java/org/chromium/distiller/DomUtil.java
|
| index 98d95f5e87d7fffaf63622b46c06501c8983af6a..79ed52ff4d6ea72756610464861dd9dc9512dc6e 100644
|
| --- a/java/org/chromium/distiller/DomUtil.java
|
| +++ b/java/org/chromium/distiller/DomUtil.java
|
| @@ -418,6 +418,7 @@ public class DomUtil {
|
| /**
|
| * Strips some attribute from certain tags in the tree rooted at |rootNode|, including root.
|
| * @param tagNames The tag names to be processed. ["*"] means all.
|
| + * TODO(crbug.com/654108): We should convert to whitelisting for all the tags.
|
| */
|
| @SuppressWarnings("unused")
|
| public static void stripAttributeFromTags(Node rootNode, String attribute, String[] tagNames) {
|
| @@ -474,6 +475,32 @@ public class DomUtil {
|
| }
|
|
|
| /**
|
| + * Strips unwanted classNames from all nodes in the tree rooted at |root|.
|
| + * TODO(crbug.com/654109): "caption" is essential for styling, but all classNames should
|
| + * be removed eventually.
|
| + */
|
| + public static void stripUnwantedClassNames(Node root) {
|
| + if (root.getNodeType() == Node.ELEMENT_NODE) {
|
| + Element element = Element.as(root);
|
| + if (element.hasAttribute("class")) {
|
| + stripUnwantedClassName(element);
|
| + }
|
| + }
|
| + NodeList<Element> elems = DomUtil.querySelectorAll(root, "[class]");
|
| + for (int i = 0; i < elems.getLength(); i++) {
|
| + stripUnwantedClassName(elems.getItem(i));
|
| + }
|
| + }
|
| +
|
| + private static void stripUnwantedClassName(Element elem) {
|
| + if (elem.getClassName().contains("caption")) {
|
| + elem.setClassName("caption");
|
| + } else {
|
| + elem.removeAttribute("class");
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Get a list of relevant nodes from a subtree.
|
| * @param root The root of the subtree.
|
| * @return A list of relevant nodes.
|
|
|