OLD | NEW |
1 package org.chromium.distiller.webdocument; | 1 package org.chromium.distiller.webdocument; |
2 | 2 |
3 import java.util.HashSet; | 3 import java.util.HashSet; |
4 import java.util.Set; | 4 import java.util.Set; |
5 | 5 |
6 /** | 6 /** |
7 * This class represents HTML tags that need to be preserved over | 7 * This class represents HTML tags that need to be preserved over |
8 * the distillation process. | 8 * the distillation process. |
9 */ | 9 */ |
10 public class WebTag extends WebElement { | 10 public class WebTag extends WebElement { |
11 private String tagName; | 11 private String tagName; |
12 private TagType tagType; | 12 private TagType tagType; |
13 | 13 |
14 public enum TagType { | 14 public enum TagType { |
15 START, END | 15 START, END |
16 } | 16 } |
17 | 17 |
18 private static Set<String> nestingTags; | 18 private static Set<String> nestingTags; |
19 static { | 19 static { |
20 nestingTags = new HashSet<String>(); | 20 nestingTags = new HashSet<String>(); |
21 nestingTags.add("UL"); | 21 nestingTags.add("UL"); |
22 nestingTags.add("OL"); | 22 nestingTags.add("OL"); |
23 nestingTags.add("LI"); | 23 nestingTags.add("LI"); |
24 nestingTags.add("BLOCKQUOTE"); | 24 nestingTags.add("BLOCKQUOTE"); |
| 25 nestingTags.add("PRE"); |
25 } | 26 } |
26 | 27 |
27 public WebTag(String tagName, TagType tagType) { | 28 public WebTag(String tagName, TagType tagType) { |
28 this.tagName = tagName; | 29 this.tagName = tagName; |
29 this.tagType = tagType; | 30 this.tagType = tagType; |
30 } | 31 } |
31 | 32 |
32 public boolean isStartTag() { | 33 public boolean isStartTag() { |
33 return tagType == TagType.START; | 34 return tagType == TagType.START; |
34 } | 35 } |
35 | 36 |
36 public String getTagName() { | 37 public String getTagName() { |
37 return tagName; | 38 return tagName; |
38 } | 39 } |
39 | 40 |
40 @Override | 41 @Override |
41 public String generateOutput(boolean textOnly) { | 42 public String generateOutput(boolean textOnly) { |
42 if (textOnly) { | 43 if (textOnly) { |
43 return ""; | 44 return ""; |
44 } | 45 } |
45 return "<" + (isStartTag() ? "" : "/") + tagName + ">"; | 46 return "<" + (isStartTag() ? "" : "/") + tagName + ">"; |
46 } | 47 } |
47 | 48 |
48 public static boolean canBeNested(String tagName) { | 49 public static boolean canBeNested(String tagName) { |
49 return nestingTags.contains(tagName); | 50 return nestingTags.contains(tagName); |
50 } | 51 } |
51 } | 52 } |
OLD | NEW |