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

Unified Diff: pkg/third_party/html5lib/lib/dom_parsing.dart

Issue 178303009: [html5lib] api updates: localName (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | « pkg/third_party/html5lib/lib/dom.dart ('k') | pkg/third_party/html5lib/lib/parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/third_party/html5lib/lib/dom_parsing.dart
diff --git a/pkg/third_party/html5lib/lib/dom_parsing.dart b/pkg/third_party/html5lib/lib/dom_parsing.dart
index fa13261ee25e32bad381d79303902da0e9e1d2db..aed9fffe2378cd3f2146e0947f9120e6729faaf4 100644
--- a/pkg/third_party/html5lib/lib/dom_parsing.dart
+++ b/pkg/third_party/html5lib/lib/dom_parsing.dart
@@ -3,6 +3,7 @@
library dom_parsing;
import 'dom.dart';
+import 'src/constants.dart' show rcdataElements;
/// A simple tree visitor for the DOM nodes.
class TreeVisitor {
@@ -67,17 +68,17 @@ class CodeMarkupVisitor extends TreeVisitor {
}
visitDocumentType(DocumentType node) {
- _str.write('<code class="markup doctype">&lt;!DOCTYPE ${node.tagName}>'
+ _str.write('<code class="markup doctype">&lt;!DOCTYPE ${node.name}>'
'</code>');
}
visitText(Text node) {
- // TODO(jmesserly): would be nice to use _addOuterHtml directly.
- _str.write(node.outerHtml);
+ writeTextNodeAsHtml(_str, node);
}
visitElement(Element node) {
- _str.write('&lt;<code class="markup element-name">${node.tagName}</code>');
+ final tag = node.localName;
+ _str.write('&lt;<code class="markup element-name">$tag</code>');
if (node.attributes.length > 0) {
node.attributes.forEach((key, v) {
v = htmlSerializeEscape(v, attributeMode: true);
@@ -88,12 +89,12 @@ class CodeMarkupVisitor extends TreeVisitor {
if (node.nodes.length > 0) {
_str.write(">");
visitChildren(node);
- } else if (isVoidElement(node.tagName)) {
+ } else if (isVoidElement(tag)) {
_str.write(">");
return;
}
_str.write(
- '&lt;/<code class="markup element-name">${node.tagName}</code>>');
+ '&lt;/<code class="markup element-name">$tag</code>>');
}
visitComment(Comment node) {
@@ -160,3 +161,18 @@ bool isVoidElement(String tagName) {
}
return false;
}
+
+/// Serialize text node according to:
+/// <http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm>
+void writeTextNodeAsHtml(StringBuffer str, Text node) {
+ // Don't escape text for certain elements, notably <script>.
+ final parent = node.parent;
+ if (parent is Element) {
+ var tag = parent.localName;
+ if (rcdataElements.contains(tag) || tag == 'plaintext') {
+ str.write(node.data);
+ return;
+ }
+ }
+ str.write(htmlSerializeEscape(node.data));
+}
« 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