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

Side by Side Diff: pkg/third_party/html5lib/lib/dom_parsing.dart

Issue 268623002: [html5lib] implement querySelector/querySelectorAll (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/third_party/html5lib/lib/dom.dart ('k') | pkg/third_party/html5lib/lib/parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// This library contains extra APIs that aren't in the DOM, but are useful 1 /// This library contains extra APIs that aren't in the DOM, but are useful
2 /// when interacting with the parse tree. 2 /// when interacting with the parse tree.
3 library dom_parsing; 3 library dom_parsing;
4 4
5 import 'dom.dart'; 5 import 'dom.dart';
6 import 'src/constants.dart' show rcdataElements; 6 import 'src/constants.dart' show rcdataElements;
7 7
8 /// A simple tree visitor for the DOM nodes. 8 /// A simple tree visitor for the DOM nodes.
9 class TreeVisitor { 9 class TreeVisitor {
10 visit(Node node) { 10 visit(Node node) {
(...skipping 22 matching lines...) Expand all
33 33
34 visitDocumentType(DocumentType node) => visitNodeFallback(node); 34 visitDocumentType(DocumentType node) => visitNodeFallback(node);
35 35
36 visitText(Text node) => visitNodeFallback(node); 36 visitText(Text node) => visitNodeFallback(node);
37 37
38 // TODO(jmesserly): visit attributes. 38 // TODO(jmesserly): visit attributes.
39 visitElement(Element node) => visitNodeFallback(node); 39 visitElement(Element node) => visitNodeFallback(node);
40 40
41 visitComment(Comment node) => visitNodeFallback(node); 41 visitComment(Comment node) => visitNodeFallback(node);
42 42
43 // Note: visits document by default because DocumentFragment is a Document. 43 visitDocumentFragment(DocumentFragment node) => visitNodeFallback(node);
44 visitDocumentFragment(DocumentFragment node) => visitDocument(node);
45 } 44 }
46 45
47 /// Converts the DOM tree into an HTML string with code markup suitable for 46 /// Converts the DOM tree into an HTML string with code markup suitable for
48 /// displaying the HTML's source code with CSS colors for different parts of the 47 /// displaying the HTML's source code with CSS colors for different parts of the
49 /// markup. See also [CodeMarkupVisitor]. 48 /// markup. See also [CodeMarkupVisitor].
50 String htmlToCodeMarkup(Node node) { 49 String htmlToCodeMarkup(Node node) {
51 return (new CodeMarkupVisitor()..visit(node)).toString(); 50 return (new CodeMarkupVisitor()..visit(node)).toString();
52 } 51 }
53 52
54 /// Converts the DOM tree into an HTML string with code markup suitable for 53 /// Converts the DOM tree into an HTML string with code markup suitable for
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 case "wbr": 158 case "wbr":
160 return true; 159 return true;
161 } 160 }
162 return false; 161 return false;
163 } 162 }
164 163
165 /// Serialize text node according to: 164 /// Serialize text node according to:
166 /// <http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#ht ml-fragment-serialization-algorithm> 165 /// <http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#ht ml-fragment-serialization-algorithm>
167 void writeTextNodeAsHtml(StringBuffer str, Text node) { 166 void writeTextNodeAsHtml(StringBuffer str, Text node) {
168 // Don't escape text for certain elements, notably <script>. 167 // Don't escape text for certain elements, notably <script>.
169 final parent = node.parent; 168 final parent = node.parentNode;
170 if (parent is Element) { 169 if (parent is Element) {
171 var tag = parent.localName; 170 var tag = parent.localName;
172 if (rcdataElements.contains(tag) || tag == 'plaintext') { 171 if (rcdataElements.contains(tag) || tag == 'plaintext') {
173 str.write(node.data); 172 str.write(node.data);
174 return; 173 return;
175 } 174 }
176 } 175 }
177 str.write(htmlSerializeEscape(node.data)); 176 str.write(htmlSerializeEscape(node.data));
178 } 177 }
OLDNEW
« no previous file with comments | « pkg/third_party/html5lib/lib/dom.dart ('k') | pkg/third_party/html5lib/lib/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698