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));
}
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 "";
}
Aggregations