Search in sources :

Example 11 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project symja_android_library by axkr.

the class DocumentationPod method generateHTMLString.

private static String generateHTMLString(final String markdownStr) {
    Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create());
    Parser parser = Parser.builder().extensions(EXTENSIONS).build();
    Node document = parser.parse(markdownStr);
    HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build();
    return renderer.render(document);
}
Also used : Extension(org.commonmark.Extension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 12 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project symja_android_library by axkr.

the class RenderMarkdown method main.

public static void main(String[] args) {
    Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create());
    Parser parser = Parser.builder().extensions(EXTENSIONS).build();
    Node document = parser.parse(TABLE);
    HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build();
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : Extension(org.commonmark.Extension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 13 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project diary by billthefarmer.

the class Diary method updateWidgets.

// updateWidgets
@SuppressWarnings("deprecation")
private void updateWidgets(CharSequence text) {
    Calendar today = Calendar.getInstance();
    if (currEntry != null && currEntry.get(Calendar.YEAR) == today.get(Calendar.YEAR) && currEntry.get(Calendar.MONTH) == today.get(Calendar.MONTH) && currEntry.get(Calendar.DATE) == today.get(Calendar.DATE)) {
        // Get date
        DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM);
        String date = format.format(today.getTime());
        if (markdown) {
            // Use commonmark
            Parser parser = Parser.builder().build();
            Node document = parser.parse(text.toString());
            HtmlRenderer renderer = HtmlRenderer.builder().build();
            String html = renderer.render(document);
            text = Html.fromHtml(html);
        }
        AppWidgetManager manager = AppWidgetManager.getInstance(this);
        ComponentName provider = new ComponentName(this, DiaryWidgetProvider.class);
        RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
        views.setTextViewText(R.id.header, date);
        views.setTextViewText(R.id.entry, text);
        manager.updateAppWidget(provider, views);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) DateFormat(java.text.DateFormat) Node(org.commonmark.node.Node) AppWidgetManager(android.appwidget.AppWidgetManager) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) ComponentName(android.content.ComponentName) Parser(org.commonmark.parser.Parser)

Aggregations

Parser (org.commonmark.parser.Parser)13 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)13 Node (org.commonmark.node.Node)12 Extension (org.commonmark.Extension)5 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 AppWidgetManager (android.appwidget.AppWidgetManager)1 ComponentName (android.content.ComponentName)1 SharedPreferences (android.content.SharedPreferences)1 RemoteViews (android.widget.RemoteViews)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MagiskManager (com.topjohnwu.magisk.MagiskManager)1 EmojiParser (com.vdurmont.emoji.EmojiParser)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1