Markdown simplification

pull/214/head
M66B 10 months ago
parent 233c7030b7
commit f6895c1ff8

@ -2343,6 +2343,7 @@ public class FragmentCompose extends FragmentBase {
private void onMenuMarkdown() { private void onMenuMarkdown() {
markdown = !markdown; markdown = !markdown;
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putBoolean("markdown", true); args.putBoolean("markdown", true);
args.putBoolean("show", true); args.putBoolean("show", true);
@ -6206,9 +6207,6 @@ public class FragmentCompose extends FragmentBase {
Elements ref = doc.select("div[fairemail=reference]"); Elements ref = doc.select("div[fairemail=reference]");
ref.remove(); ref.remove();
boolean markdown = Boolean.parseBoolean(doc.body().attr("markdown"));
args.putBoolean("markdown", markdown);
File refFile = data.draft.getRefFile(context); File refFile = data.draft.getRefFile(context);
if (refFile.exists()) { if (refFile.exists()) {
ref.html(Helper.readText(refFile)); ref.html(Helper.readText(refFile));
@ -6281,7 +6279,6 @@ public class FragmentCompose extends FragmentBase {
working = data.draft.id; working = data.draft.id;
dsn = (data.draft.dsn != null && !EntityMessage.DSN_NONE.equals(data.draft.dsn)); dsn = (data.draft.dsn != null && !EntityMessage.DSN_NONE.equals(data.draft.dsn));
encrypt = data.draft.ui_encrypt; encrypt = data.draft.ui_encrypt;
markdown = args.getBoolean("markdown");
invalidateOptionsMenu(); invalidateOptionsMenu();
subject = data.draft.subject; subject = data.draft.subject;
@ -6722,12 +6719,11 @@ public class FragmentCompose extends FragmentBase {
Document doc = JsoupEx.parse(html); Document doc = JsoupEx.parse(html);
doc.body().attr("markdown", Boolean.toString(markdown)); doc.body().attr("markdown", Boolean.toString(markdown));
body = doc.html(); body = doc.html();
} else { } else
body = (convertMarkdown body = (convertMarkdown
? Markdown.toHtml(spanned.toString()) ? Markdown.toHtml(spanned.toString())
: HtmlHelper.toHtml(spanned, context)); : HtmlHelper.toHtml(spanned, context));
} if (convertMarkdown)
if (markdown ^ convertMarkdown)
dirty = true; dirty = true;
EntityMessage draft; EntityMessage draft;
@ -7637,15 +7633,12 @@ public class FragmentCompose extends FragmentBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", draft.id); args.putLong("id", draft.id);
args.putBoolean("show_images", show_images); args.putBoolean("show_images", show_images);
args.putBoolean("markdown", markdown);
new SimpleTask<Spanned[]>() { new SimpleTask<Spanned[]>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
// Needed to get width for images // Needed to get width for images
grpBody.setVisibility(View.VISIBLE); grpBody.setVisibility(View.VISIBLE);
if (markwonWatcher != null)
etBody.removeTextChangedListener(markwonWatcher);
} }
@Override @Override
@ -7661,18 +7654,12 @@ public class FragmentCompose extends FragmentBase {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
invalidateOptionsMenu(); invalidateOptionsMenu();
if (markdown && markwonWatcher != null) {
etBody.addTextChangedListener(markwonWatcher);
markwonWatcher.afterTextChanged(etBody.getText());
}
} }
@Override @Override
protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable { protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable {
final long id = args.getLong("id"); final long id = args.getLong("id");
final boolean show_images = args.getBoolean("show_images", false); final boolean show_images = args.getBoolean("show_images", false);
final boolean markdown = args.getBoolean("markdown", false);
int colorPrimary = Helper.resolveColor(context, androidx.appcompat.R.attr.colorPrimary); int colorPrimary = Helper.resolveColor(context, androidx.appcompat.R.attr.colorPrimary);
final int colorBlockquote = Helper.resolveColor(context, R.attr.colorBlockquote, colorPrimary); final int colorBlockquote = Helper.resolveColor(context, R.attr.colorBlockquote, colorPrimary);
@ -7689,6 +7676,9 @@ public class FragmentCompose extends FragmentBase {
Elements ref = doc.select("div[fairemail=reference]"); Elements ref = doc.select("div[fairemail=reference]");
ref.remove(); ref.remove();
boolean markdown = Boolean.parseBoolean(doc.body().attr("markdown"));
args.putBoolean("markdown", markdown);
Spanned spannedBody; Spanned spannedBody;
if (markdown) { if (markdown) {
String md = Markdown.fromHtml(doc.body().html()); String md = Markdown.fromHtml(doc.body().html());
@ -7760,6 +7750,15 @@ public class FragmentCompose extends FragmentBase {
@Override @Override
protected void onExecuted(Bundle args, Spanned[] text) { protected void onExecuted(Bundle args, Spanned[] text) {
markdown = args.getBoolean("markdown");
invalidateOptionsMenu();
if (markwonWatcher != null)
if (markdown)
etBody.addTextChangedListener(markwonWatcher);
else
etBody.removeTextChangedListener(markwonWatcher);
etBody.setText(text[0]); etBody.setText(text[0]);
etBody.setTag(text[0]); etBody.setTag(text[0]);

Loading…
Cancel
Save