"); + @override + void visitDocument(Document node) { + _str.write(''); } - visitDocumentType(DocumentType node) { + @override + void visitDocumentType(DocumentType node) { _str.write(''); visitChildren(node); - _str.write(""); + _str.write('
<!DOCTYPE ${node.name}>'
'
');
}
- visitText(Text node) {
+ @override
+ void visitText(Text node) {
writeTextNodeAsHtml(_str, node);
}
- visitElement(Element node) {
+ @override
+ void visitElement(Element node) {
final tag = node.localName;
_str.write('<$tag
');
if (node.attributes.isNotEmpty) {
@@ -95,16 +100,17 @@ class CodeMarkupVisitor extends TreeVisitor {
});
}
if (node.nodes.isNotEmpty) {
- _str.write(">");
+ _str.write('>');
visitChildren(node);
} else if (isVoidElement(tag)) {
- _str.write(">");
+ _str.write('>');
return;
}
_str.write('</$tag
>');
}
- visitComment(Comment node) {
+ @override
+ void visitComment(Comment node) {
var data = htmlSerializeEscape(node.data);
_str.write('<!--$data-->
');
}
@@ -131,7 +137,7 @@ String htmlSerializeEscape(String text, {bool attributeMode = false}) {
// TODO(jmesserly): is it faster to build up a list of codepoints?
// StringBuffer seems cleaner assuming Dart can unbox 1-char strings.
StringBuffer result;
- for (int i = 0; i < text.length; i++) {
+ for (var i = 0; i < text.length; i++) {
var ch = text[i];
String replace;
switch (ch) {
@@ -152,7 +158,7 @@ String htmlSerializeEscape(String text, {bool attributeMode = false}) {
break;
}
if (replace != null) {
- if (result == null) result = StringBuffer(text.substring(0, i));
+ result ??= StringBuffer(text.substring(0, i));
result.write(replace);
} else if (result != null) {
result.write(ch);
@@ -168,22 +174,22 @@ String htmlSerializeEscape(String text, {bool attributeMode = false}) {
/// See also: