Fixed removing trailing whitespace

This is important for right alignment
This commit is contained in:
M66B 2020-05-16 16:27:37 +02:00
parent d08cfb6938
commit a091779302
1 changed files with 22 additions and 4 deletions

View File

@ -1826,6 +1826,8 @@ public class HtmlHelper {
for (int i = 0; i < block.size(); ) { for (int i = 0; i < block.size(); ) {
tnode = block.get(i); tnode = block.get(i);
text = tnode.getWholeText(); text = tnode.getWholeText();
if (text.contains("7,80"))
Log.i("Here");
if ("-- ".equals(text)) { if ("-- ".equals(text)) {
i++; i++;
@ -1835,14 +1837,11 @@ public class HtmlHelper {
// Remove whitespace before/after newlines // Remove whitespace before/after newlines
text = TRIM_WHITESPACE_NL.matcher(text).replaceAll(" "); text = TRIM_WHITESPACE_NL.matcher(text).replaceAll(" ");
// Remove leading whitespace
if (i == 0 || endsWithWhitespace(block.get(i - 1).text())) if (i == 0 || endsWithWhitespace(block.get(i - 1).text()))
while (startsWithWhiteSpace(text)) while (startsWithWhiteSpace(text))
text = text.substring(1); text = text.substring(1);
if (i == block.size() - 1)
while (endsWithWhitespace(text))
text = text.substring(0, text.length() - 1);
tnode.text(text); tnode.text(text);
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
@ -1851,6 +1850,25 @@ public class HtmlHelper {
i++; i++;
} }
// Remove trailing whitespace
int i = block.size();
while (i > 0) {
tnode = block.get(i - 1);
text = tnode.getWholeText();
if (endsWithWhitespace(text)) {
while (endsWithWhitespace(text))
text = text.substring(0, text.length() - 1);
tnode.text(text);
if (TextUtils.isEmpty(text))
i--;
else
break;
} else
break;
}
if (debug) { if (debug) {
if (block.size() > 0) { if (block.size() > 0) {
TextNode first = block.get(0); TextNode first = block.get(0);