Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: java/org/chromium/distiller/DomUtil.java

Issue 2401853004: Strip unwanted classNames from all nodes (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | java/org/chromium/distiller/webdocument/WebText.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | java/org/chromium/distiller/webdocument/WebText.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698