| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library trydart.htmlToText; | 5 library trydart.htmlToText; |
| 6 | 6 |
| 7 import 'dart:math' show | 7 import 'dart:math' show |
| 8 max; | 8 max; |
| 9 | 9 |
| 10 import 'dart:html' show | 10 import 'dart:html' show |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /// Returns true if [node] is a block element, that is, not inline. | 26 /// Returns true if [node] is a block element, that is, not inline. |
| 27 bool isBlockElement(Node node) { | 27 bool isBlockElement(Node node) { |
| 28 if (node is! Element) return false; | 28 if (node is! Element) return false; |
| 29 Element element = node; | 29 Element element = node; |
| 30 | 30 |
| 31 // TODO(ahe): Remove this line by changing code completion to avoid using a | 31 // TODO(ahe): Remove this line by changing code completion to avoid using a |
| 32 // div element. | 32 // div element. |
| 33 if (element.classes.contains('dart-code-completion')) return false; | 33 if (element.classes.contains('dart-code-completion')) return false; |
| 34 | 34 |
| 35 return element.getComputedStyle().display != 'inline'; | 35 var display = element.getComputedStyle().display; |
| 36 return display != 'inline' && display != 'none'; |
| 36 } | 37 } |
| 37 | 38 |
| 38 /// Writes the text of [root] to [buffer]. Keeps track of [selection] and | 39 /// Writes the text of [root] to [buffer]. Keeps track of [selection] and |
| 39 /// returns the new anchorOffset from beginning of [buffer] or -1 if the | 40 /// returns the new anchorOffset from beginning of [buffer] or -1 if the |
| 40 /// selection isn't in [root]. | 41 /// selection isn't in [root]. |
| 41 int htmlToText(Node root, | 42 int htmlToText(Node root, |
| 42 StringBuffer buffer, | 43 StringBuffer buffer, |
| 43 TrySelection selection, | 44 TrySelection selection, |
| 44 {bool treatRootAsInline: false}) { | 45 {bool treatRootAsInline: false}) { |
| 45 int selectionOffset = -1; | 46 int selectionOffset = -1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 | 68 |
| 68 return WALKER_NEXT; | 69 return WALKER_NEXT; |
| 69 }); | 70 }); |
| 70 | 71 |
| 71 if (!treatRootAsInline && isBlockElement(root)) { | 72 if (!treatRootAsInline && isBlockElement(root)) { |
| 72 buffer.write('\n'); | 73 buffer.write('\n'); |
| 73 } | 74 } |
| 74 | 75 |
| 75 return selectionOffset; | 76 return selectionOffset; |
| 76 } | 77 } |
| OLD | NEW |