mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 13:03:37 +00:00
Read full css into memory for MarkdownWindow
This commit is contained in:
parent
f17792380b
commit
d34bd47bea
@ -38,12 +38,12 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... voids) {
|
protected String doInBackground(Void... voids) {
|
||||||
|
MagiskManager mm = MagiskManager.get();
|
||||||
String md;
|
String md;
|
||||||
if (mUrl != null) {
|
if (mUrl != null) {
|
||||||
md = WebService.getString(mUrl);
|
md = WebService.getString(mUrl);
|
||||||
} else {
|
} else {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
try {
|
|
||||||
Utils.inToOut(is, out);
|
Utils.inToOut(is, out);
|
||||||
md = out.toString();
|
md = out.toString();
|
||||||
is.close();
|
is.close();
|
||||||
@ -52,12 +52,21 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String css;
|
||||||
|
try (
|
||||||
|
InputStream in = mm.getAssets().open(mm.isDarkTheme ? "dark.css" : "light.css");
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
||||||
|
) {
|
||||||
|
Utils.inToOut(in, out);
|
||||||
|
css = out.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
Parser parser = Parser.builder().build();
|
Parser parser = Parser.builder().build();
|
||||||
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
||||||
Node doc = parser.parse(md);
|
Node doc = parser.parse(md);
|
||||||
return String.format(
|
return String.format("<style>%s</style>%s", css, renderer.render(doc));
|
||||||
"<link rel='stylesheet' type='text/css' href='file:///android_asset/%s.css'/> %s",
|
|
||||||
MagiskManager.get().isDarkTheme ? "dark" : "light", renderer.render(doc));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user