Search in sources :

Example 41 with Node

use of org.commonmark.node.Node 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 42 with Node

use of org.commonmark.node.Node 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

Node (org.commonmark.node.Node)42 Parser (org.commonmark.parser.Parser)18 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)12 Test (org.junit.Test)9 Extension (org.commonmark.Extension)7 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)7 IOException (java.io.IOException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DateFormat (java.text.DateFormat)2 HashMap (java.util.HashMap)2 TableBlock (org.commonmark.ext.gfm.tables.TableBlock)2 Code (org.commonmark.node.Code)2 CustomNode (org.commonmark.node.CustomNode)2 AppWidgetManager (android.appwidget.AppWidgetManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1