Fixed removing trailing whitespace

This is important for right alignment
pull/178/head
M66B 5 years ago
parent d08cfb6938
commit a091779302

@ -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,20 +1837,36 @@ 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) tnode.text(text);
if (TextUtils.isEmpty(text))
block.remove(i);
else
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)) while (endsWithWhitespace(text))
text = text.substring(0, text.length() - 1); text = text.substring(0, text.length() - 1);
tnode.text(text); tnode.text(text);
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
block.remove(i); i--;
else else
i++; break;
} else
break;
} }
if (debug) { if (debug) {

Loading…
Cancel
Save