Added Markdown table support

pull/214/head
M66B 10 months ago
parent f30ad34aa3
commit cec15d6079

@ -485,6 +485,9 @@ configurations.configureEach {
// paging-runtime: AsyncPagedListDiffer, LivePagedListBuilder, PagedListAdapter, PagedStorageDiffHelper
exclude group: "androidx.emoji2", module: "emoji2"
// Markwon
exclude group: "com.atlassian.commonmark", module: "commonmark"
}
configurations.configureEach {
@ -557,6 +560,7 @@ dependencies {
def vcard_version = "0.12.1"
def relinker_version = "1.4.5"
def markwon_version = "4.6.2"
def commonmark_version = "0.21.0"
def bouncycastle_version = "1.77"
def colorpicker_version = "0.0.15"
def overscroll_version = "1.1.1"
@ -767,6 +771,12 @@ dependencies {
implementation "io.noties.markwon:html:$markwon_version"
implementation "io.noties.markwon:editor:$markwon_version"
// https://github.com/commonmark/commonmark-java
// https://mvnrepository.com/artifact/org.commonmark
implementation "org.commonmark:commonmark:$commonmark_version";
implementation "org.commonmark:commonmark-ext-gfm-tables:$commonmark_version";
implementation "org.commonmark:commonmark-ext-gfm-strikethrough:$commonmark_version";
// // https://github.com/QuadFlask/colorpicker
//implementation "com.github.QuadFlask:colorpicker:$colorpicker_version"
implementation project(':colorpicker')

@ -19,16 +19,29 @@ package eu.faircode.email;
Copyright 2018-2024 by Marcel Bokhorst (M66B)
*/
import org.commonmark.Extension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.jsoup.nodes.Document;
import java.util.Arrays;
import java.util.List;
public class Markdown {
static String toHtml(String markdown) {
Parser p = Parser.builder().build();
List<Extension> extensions = Arrays.asList(
TablesExtension.create(),
StrikethroughExtension.create());
Parser p = Parser.builder()
.extensions(extensions)
.build();
Node d = p.parse(markdown);
HtmlRenderer r = HtmlRenderer.builder().build();
HtmlRenderer r = HtmlRenderer.builder()
.extensions(extensions)
.build();
return r.render(d);
}

Loading…
Cancel
Save