Only collapse runs of space, tab, carriage return, and newline
Closes #184
This commit is contained in:
parent
5152581a0c
commit
82cd2d92e1
2 changed files with 17 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ public class ComposerWebViewTest : ClientWebViewTestCase<ComposerWebView> {
|
|||
add_test("get_text_with_nbsp", get_text_with_nbsp);
|
||||
add_test("get_text_with_named_link", get_text_with_named_link);
|
||||
add_test("get_text_with_url_link", get_text_with_named_link);
|
||||
add_test("get_text_with_surrounding_nbsps", get_text_with_surrounding_nbsps);
|
||||
}
|
||||
|
||||
public void load_resources() throws Error {
|
||||
|
|
@ -197,6 +198,18 @@ long, long, long, long, long, long, long, long, long, long,
|
|||
}
|
||||
}
|
||||
|
||||
public void get_text_with_surrounding_nbsps() throws Error {
|
||||
load_body_fixture(" I like my space ");
|
||||
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
||||
try {
|
||||
assert(this.test_view.get_text.end(async_result()) ==
|
||||
" I like my space\n\n\n\n");
|
||||
} catch (Error err) {
|
||||
print("Error: %s\n", err.message);
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
protected override ComposerWebView set_up_test_view() {
|
||||
return new ComposerWebView(this.config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,8 +473,10 @@ ComposerPageState.htmlToText = function(root) {
|
|||
case 'normal':
|
||||
case 'nowrap':
|
||||
case 'pre-line':
|
||||
nodeText = nodeText.replace(/\s+/g, " ");
|
||||
if (nodeText == " " && /\s/.test(text.substr(-1)))
|
||||
// Only space, tab, carriage return, and newline collapse
|
||||
// https://www.w3.org/TR/2011/REC-CSS2-20110607/text.html#white-space-model
|
||||
nodeText = nodeText.replace(/[ \t\r\n]+/g, " ");
|
||||
if (nodeText == " " && " \t\r\n".includes(text.substr(-1)))
|
||||
break; // There's already whitespace here
|
||||
if (node == root.firstChild)
|
||||
nodeText = nodeText.replace(/^ /, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue