Chromium Code Reviews| 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..da78d4775ca21b0ee7e31d0dfe84cdd0e9823209 100644 |
| --- a/java/org/chromium/distiller/DomUtil.java |
| +++ b/java/org/chromium/distiller/DomUtil.java |
| @@ -474,6 +474,30 @@ public class DomUtil { |
| } |
| /** |
| + * Strips unwanted classNames from all nodes in the tree rooted at |root|. |
|
mdjones
2016/10/07 23:03:37
Can you mention here and in the CL description wha
wychen
2016/10/07 23:11:52
Will do.
wychen
2016/10/07 23:32:20
Done.
|
| + */ |
| + 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]"); |
|
mdjones
2016/10/07 23:03:37
Why not select all elements and iterate over the r
wychen
2016/10/07 23:11:53
Not all elements have class attribute, so skipping
|
| + for (int i = 0; i < elems.getLength(); i++) { |
| + stripUnwantedClassName(elems.getItem(i)); |
| + } |
| + } |
| + |
| + public 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. |