mirror of https://github.com/M66B/FairEmail.git
Convert to/from markdown
This commit is contained in:
parent
cc576a4c71
commit
95da049eb2
|
@ -6715,18 +6715,21 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
boolean dirty = false;
|
||||
String body;
|
||||
if (markdown ^ extras.getBoolean("markdown")) {
|
||||
String text = spanned.toString().replace('\u00a0', ' ');
|
||||
String html = Markdown.toHtml(text);
|
||||
|
||||
boolean convertMarkdown = extras.getBoolean("markdown");
|
||||
if (markdown) {
|
||||
String html = (convertMarkdown
|
||||
? HtmlHelper.toHtml(spanned, context)
|
||||
: Markdown.toHtml(spanned.toString()));
|
||||
Document doc = JsoupEx.parse(html);
|
||||
doc.body().attr("markdown", Boolean.toString(markdown));
|
||||
body = doc.html();
|
||||
|
||||
if (markdown != extras.getBoolean("markdown"))
|
||||
dirty = true;
|
||||
} else
|
||||
body = HtmlHelper.toHtml(spanned, context);
|
||||
} else {
|
||||
body = (convertMarkdown
|
||||
? Markdown.toHtml(spanned.toString())
|
||||
: HtmlHelper.toHtml(spanned, context));
|
||||
}
|
||||
if (markdown ^ convertMarkdown)
|
||||
dirty = true;
|
||||
|
||||
EntityMessage draft;
|
||||
|
||||
|
@ -7689,7 +7692,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
Spanned spannedBody;
|
||||
if (markdown) {
|
||||
String md = Markdown.fromHtml(doc);
|
||||
String md = Markdown.fromHtml(doc.body().html());
|
||||
spannedBody = new SpannableStringBuilder(md);
|
||||
} else {
|
||||
HtmlHelper.clearAnnotations(doc); // Legacy left-overs
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.List;
|
|||
|
||||
public class Markdown {
|
||||
static String toHtml(String markdown) {
|
||||
markdown = markdown.replace('\u00a0', ' ');
|
||||
List<Extension> extensions = Arrays.asList(
|
||||
TablesExtension.create(),
|
||||
StrikethroughExtension.create());
|
||||
|
@ -45,7 +46,7 @@ public class Markdown {
|
|||
return r.render(d);
|
||||
}
|
||||
|
||||
static String fromHtml(Document d) {
|
||||
static String fromHtml(String html) {
|
||||
// TODO: HTML to Markdown
|
||||
throw new IllegalArgumentException("Not implemented");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue