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

Unified Diff: dart/site/try/src/html_to_text.dart

Issue 274563011: Ignore non-content divs in htmlToText. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/site/try/src/html_to_text.dart
diff --git a/dart/site/try/src/html_to_text.dart b/dart/site/try/src/html_to_text.dart
index 3b5dbb555ca793e04a8ca1a3729151fc0168ae07..aa8710d828dba52da8303b2c3494f15d41b473aa 100644
--- a/dart/site/try/src/html_to_text.dart
+++ b/dart/site/try/src/html_to_text.dart
@@ -22,6 +22,11 @@ import 'selection.dart' show
bool isBlockElement(Node node) {
if (node is! Element) return false;
Element element = node;
+
+ // TODO(ahe): Remove this line by changing code completion to avoid using a
+ // div element.
+ if (element.classes.contains('dart-code-completion')) return false;
+
return element.getComputedStyle().display != 'inline';
}
@@ -46,7 +51,10 @@ void skip(Node node, TreeWalker walker) {
/// Writes the text of [root] to [buffer]. Keeps track of [selection] and
/// returns the new anchorOffset from beginning of [buffer] or -1 if the
/// selection isn't in [root].
-int htmlToText(Node root, StringBuffer buffer, TrySelection selection) {
+int htmlToText(Node root,
+ StringBuffer buffer,
+ TrySelection selection,
+ {bool treatRootAsInline: false}) {
int selectionOffset = -1;
TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_ALL);
@@ -77,7 +85,7 @@ int htmlToText(Node root, StringBuffer buffer, TrySelection selection) {
}
}
- if (isBlockElement(root)) {
+ if (!treatRootAsInline && isBlockElement(root)) {
buffer.write('\n');
}
« no previous file with comments | « no previous file | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698