Paste plain text without quoting

pull/178/head
M66B 5 years ago
parent 7c00859a58
commit 0ba3e9e9df

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

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

Loading…
Cancel
Save