Search in sources :

Example 11 with Parser

use of org.commonmark.parser.Parser in project MagiskManager by topjohnwu.

the class MarkDownWindow method doInBackground.

@Override
protected String doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    String md;
    if (mUrl != null) {
        md = WebService.getString(mUrl);
    } else {
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            ShellUtils.pump(is, out);
            md = out.toString();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
    String css;
    try (InputStream in = mm.getResources().openRawResource(mm.isDarkTheme ? R.raw.dark : R.raw.light);
        ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        ShellUtils.pump(in, out);
        css = out.toString();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    Node doc = parser.parse(md);
    return String.format("<style>%s</style>%s", css, renderer.render(doc));
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) InputStream(java.io.InputStream) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Parser(org.commonmark.parser.Parser)

Example 12 with Parser

use of org.commonmark.parser.Parser in project FastHub by k0shk0sh.

the class MarkDownProvider method stripMdText.

@NonNull
public static String stripMdText(String markdown) {
    if (!InputHelper.isEmpty(markdown)) {
        Parser parser = Parser.builder().build();
        Node node = parser.parse(markdown);
        return stripHtml(HtmlRenderer.builder().build().render(node));
    }
    return "";
}
Also used : Node(org.commonmark.node.Node) Parser(org.commonmark.parser.Parser) NonNull(android.support.annotation.NonNull)

Aggregations

Parser (org.commonmark.parser.Parser)12 Node (org.commonmark.node.Node)11 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)7 IOException (java.io.IOException)2 Extension (org.commonmark.Extension)2 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1