diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index 91cd7067dc..658508f2bc 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -160,8 +160,6 @@ import org.bouncycastle.operator.RuntimeOperatorException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
import org.bouncycastle.util.Store;
-import org.commonmark.node.Node;
-import org.commonmark.renderer.html.HtmlRenderer;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@@ -6718,16 +6716,8 @@ public class FragmentCompose extends FragmentBase {
boolean dirty = false;
String body;
if (markdown ^ extras.getBoolean("markdown")) {
- // Markdown to HTML
String text = spanned.toString().replace('\u00a0', ' ');
-
- Markwon markwon = Markwon.builder(context)
- .usePlugin(HtmlPlugin.create())
- .build();
- Node document = markwon.parse(text);
-
- HtmlRenderer renderer = HtmlRenderer.builder().build();
- String html = renderer.render(document);
+ String html = Markdown.toHtml(text);
Document doc = JsoupEx.parse(html);
doc.body().attr("markdown", Boolean.toString(markdown));
@@ -7699,8 +7689,8 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedBody;
if (markdown) {
- // TODO: HTML to Markdown
- spannedBody = new SpannableStringBuilder(doc.html());
+ String md = Markdown.fromHtml(doc);
+ spannedBody = new SpannableStringBuilder(md);
} else {
HtmlHelper.clearAnnotations(doc); // Legacy left-overs
diff --git a/app/src/main/java/eu/faircode/email/Markdown.java b/app/src/main/java/eu/faircode/email/Markdown.java
new file mode 100644
index 0000000000..0407f3a60c
--- /dev/null
+++ b/app/src/main/java/eu/faircode/email/Markdown.java
@@ -0,0 +1,39 @@
+package eu.faircode.email;
+
+/*
+ This file is part of FairEmail.
+
+ FairEmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ FairEmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with FairEmail. If not, see