pull/214/head
M66B 6 months ago
parent 0731caad31
commit d22dbfcdd9

@ -772,12 +772,6 @@ dependencies {
implementation "io.noties.markwon:html:$markwon_version" implementation "io.noties.markwon:html:$markwon_version"
implementation "io.noties.markwon:editor:$markwon_version" implementation "io.noties.markwon:editor:$markwon_version"
// https://github.com/vsch/flexmark-java
// https://mvnrepository.com/artifact/com.vladsch.flexmark/flexmark
//implementation "com.vladsch.flexmark:flexmark:$flexmark_version"
//implementation "com.vladsch.flexmark:flexmark-ext-tables:$flexmark_version"
//implementation "com.vladsch.flexmark:flexmark-html2md-converter:$flexmark_version"
// // https://github.com/QuadFlask/colorpicker // // https://github.com/QuadFlask/colorpicker
//implementation "com.github.QuadFlask:colorpicker:$colorpicker_version" //implementation "com.github.QuadFlask:colorpicker:$colorpicker_version"
implementation project(':colorpicker') implementation project(':colorpicker')

@ -160,6 +160,8 @@ import org.bouncycastle.operator.RuntimeOperatorException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder; import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
import org.bouncycastle.util.Store; 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.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
@ -230,6 +232,7 @@ import biweekly.property.Organizer;
import io.noties.markwon.Markwon; import io.noties.markwon.Markwon;
import io.noties.markwon.editor.MarkwonEditor; import io.noties.markwon.editor.MarkwonEditor;
import io.noties.markwon.editor.MarkwonEditorTextWatcher; import io.noties.markwon.editor.MarkwonEditorTextWatcher;
import io.noties.markwon.html.HtmlPlugin;
public class FragmentCompose extends FragmentBase { public class FragmentCompose extends FragmentBase {
private enum State {NONE, LOADING, LOADED} private enum State {NONE, LOADING, LOADED}
@ -2021,7 +2024,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_media).setChecked(media); menu.findItem(R.id.menu_media).setChecked(media);
menu.findItem(R.id.menu_compact).setChecked(compact); menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_markdown).setChecked(markdown); menu.findItem(R.id.menu_markdown).setChecked(markdown);
menu.findItem(R.id.menu_markdown).setVisible(false && experiments); menu.findItem(R.id.menu_markdown).setVisible(BuildConfig.DEBUG && experiments);
View image = media_bar.findViewById(R.id.menu_image); View image = media_bar.findViewById(R.id.menu_image);
if (image != null) if (image != null)
@ -6205,7 +6208,8 @@ 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")); boolean markdown = (BuildConfig.DEBUG &&
Boolean.parseBoolean(doc.body().attr("markdown")));
args.putBoolean("markdown", markdown); args.putBoolean("markdown", markdown);
File refFile = data.draft.getRefFile(context); File refFile = data.draft.getRefFile(context);
@ -6713,17 +6717,17 @@ public class FragmentCompose extends FragmentBase {
boolean dirty = false; boolean dirty = false;
String body; String body;
if (false && (markdown ^ extras.getBoolean("markdown"))) { if (markdown ^ extras.getBoolean("markdown")) {
/* // Markdown to HTML
MutableDataSet options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(
TablesExtension.create(),
StrikethroughExtension.create()));
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
String text = spanned.toString().replace('\u00a0', ' '); String text = spanned.toString().replace('\u00a0', ' ');
String html = renderer.render(parser.parse(text));
Markwon markwon = Markwon.builder(context)
.usePlugin(HtmlPlugin.create())
.build();
Node document = markwon.parse(text);
HtmlRenderer renderer = HtmlRenderer.builder().build();
String html = renderer.render(document);
Document doc = JsoupEx.parse(html); Document doc = JsoupEx.parse(html);
doc.body().attr("markdown", Boolean.toString(markdown)); doc.body().attr("markdown", Boolean.toString(markdown));
@ -6731,7 +6735,6 @@ public class FragmentCompose extends FragmentBase {
if (markdown != extras.getBoolean("markdown")) if (markdown != extras.getBoolean("markdown"))
dirty = true; dirty = true;
*/
} else } else
body = HtmlHelper.toHtml(spanned, context); body = HtmlHelper.toHtml(spanned, context);
@ -7695,15 +7698,9 @@ public class FragmentCompose extends FragmentBase {
ref.remove(); ref.remove();
Spanned spannedBody; Spanned spannedBody;
if (false && markdown) { if (markdown) {
/* // TODO: HTML to Markdown
MutableDataSet options = new MutableDataSet(); spannedBody = new SpannableStringBuilder(doc.html());
// HtmlConverterCoreNodeRenderer
// options.set(FlexmarkHtmlConverter.LISTS_END_ON_DOUBLE_BLANK, false);
String text = FlexmarkHtmlConverter.builder(options).build().convert(doc.html());
text = text.replaceAll("\n.*<!-- -->\n\n", "");
spannedBody = new SpannableStringBuilder(text);
*/
} else { } else {
HtmlHelper.clearAnnotations(doc); // Legacy left-overs HtmlHelper.clearAnnotations(doc); // Legacy left-overs

Loading…
Cancel
Save