Paste plain text without quoting

This commit is contained in:
M66B 2020-05-22 20:07:58 +02:00
parent 7c00859a58
commit 0ba3e9e9df
2 changed files with 23 additions and 17 deletions

View File

@ -77,7 +77,7 @@ public class EditTextCompose extends FixedEditText {
CharSequence text = item.getText();
if (text == null)
return false;
html = "<div>" + HtmlHelper.formatPre(text.toString()) + "</div>";
html = "<div>" + HtmlHelper.formatPre(text.toString(), false) + "</div>";
}
Document document = HtmlHelper.sanitizeCompose(context, html, false);

View File

@ -1293,31 +1293,37 @@ public class HtmlHelper {
}
static String formatPre(String text) {
return formatPre(text, true);
}
static String formatPre(String text, boolean quote) {
int level = 0;
StringBuilder sb = new StringBuilder();
String[] lines = text.split("\\r?\\n");
for (String line : lines) {
// Opening quotes
// https://tools.ietf.org/html/rfc3676#section-4.5
int tlevel = 0;
while (line.startsWith(">")) {
tlevel++;
if (tlevel > level)
sb.append("<blockquote>");
if (quote) {
int tlevel = 0;
while (line.startsWith(">")) {
tlevel++;
if (tlevel > level)
sb.append("<blockquote>");
line = line.substring(1); // >
line = line.substring(1); // >
if (line.startsWith(" >"))
line = line.substring(1);
if (line.startsWith(" >"))
line = line.substring(1);
}
if (tlevel > 0)
if (line.length() > 0 && line.charAt(0) == ' ')
line = line.substring(1);
// Closing quotes
for (int i = 0; i < level - tlevel; i++)
sb.append("</blockquote>");
level = tlevel;
}
if (tlevel > 0)
if (line.length() > 0 && line.charAt(0) == ' ')
line = line.substring(1);
// Closing quotes
for (int i = 0; i < level - tlevel; i++)
sb.append("</blockquote>");
level = tlevel;
// Tabs characters
StringBuilder l = new StringBuilder();