Added view HTML line numbers

pull/214/head
M66B 1 year ago
parent c3386cae88
commit aa12764158

@ -1,3 +1,4 @@
/* PrismJS 1.29.0
https://prismjs.com/download.html#themes=prism-solarizedlight&languages=markup+css+clike+javascript */
https://prismjs.com/download.html#themes=prism-solarizedlight&languages=markup+css+clike+javascript&plugins=line-numbers */
code[class*=language-],pre[class*=language-]{color:#657b83;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{background:#073642}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{background:#073642}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background-color:#fdf6e3}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#93a1a1}.token.punctuation{color:#586e75}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#268bd2}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string,.token.url{color:#2aa198}.token.entity{color:#657b83;background:#eee8d5}.token.atrule,.token.attr-value,.token.keyword{color:#859900}.token.class-name,.token.function{color:#b58900}.token.important,.token.regex,.token.variable{color:#cb4b16}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}

File diff suppressed because one or more lines are too long

@ -37,8 +37,6 @@ import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.Group;
import androidx.preference.PreferenceManager;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -53,14 +51,17 @@ public class ActivityCode extends ActivityBase {
private ContentLoadingProgressBar pbWait;
private Group grpReady;
private boolean lines = BuildConfig.DEBUG;
private boolean sanitize = BuildConfig.DEBUG;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null)
if (savedInstanceState != null) {
lines = savedInstanceState.getBoolean("fair:lines");
sanitize = savedInstanceState.getBoolean("fair:sanitize");
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -107,6 +108,7 @@ public class ActivityCode extends ActivityBase {
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("fair:lines", lines);
outState.putBoolean("fair:sanitize", sanitize);
super.onSaveInstanceState(outState);
}
@ -123,6 +125,9 @@ public class ActivityCode extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean debug = prefs.getBoolean("debug", false);
menu.findItem(R.id.menu_lines)
.setChecked(lines);
menu.findItem(R.id.menu_sanitize)
.setVisible(BuildConfig.DEBUG || debug)
.setChecked(sanitize)
@ -132,6 +137,8 @@ public class ActivityCode extends ActivityBase {
.setTitle(getString(sanitize
? R.string.title_legend_show_full
: R.string.title_legend_show_reformatted));
return super.onPrepareOptionsMenu(menu);
}
@ -141,6 +148,11 @@ public class ActivityCode extends ActivityBase {
if (itemId == android.R.id.home) {
finishAndRemoveTask();
return true;
} else if (itemId == R.id.menu_lines) {
lines = !lines;
invalidateOptionsMenu();
load();
return true;
} else if (itemId == R.id.menu_sanitize) {
sanitize = !sanitize;
invalidateOptionsMenu();
@ -153,7 +165,7 @@ public class ActivityCode extends ActivityBase {
private void load() {
Intent intent = getIntent();
long id = intent.getLongExtra("id", -1L);
Log.i("Text id=" + id + " sanitize=" + sanitize);
Log.i("Show code message=" + id + " lines=" + lines + " sanitize=" + sanitize);
Bundle args = new Bundle();
args.putLong("id", id);
@ -209,17 +221,22 @@ public class ActivityCode extends ActivityBase {
protected void onExecuted(Bundle args, String code) {
getSupportActionBar().setSubtitle(args.getString("subject"));
String clazz = "language-html";
if (lines)
clazz += " line-numbers";
String html = "<!DOCTYPE html>" +
"<html>" +
"<head>" +
"<link href=\"file:///android_asset/prism.css\" rel=\"stylesheet\" />" +
"<style>" +
" code[class=\"language-html\"] { font-size: smaller !important; }" +
"</style>" +
" <meta charset=\"utf-8\" />" +
" <link href=\"file:///android_asset/prism.css\" rel=\"stylesheet\" />" +
" <style>" +
" body { font-size: smaller !important; }" +
" </style>" +
"</head>" +
"<body>" +
"<script src=\"file:///android_asset/prism.js\"></script>" +
"<code class=\"language-html\">" + Html.escapeHtml(code) + "</code>" +
" <script src=\"file:///android_asset/prism.js\"></script>" +
" <pre><code class=\"" + clazz + "\">" + Html.escapeHtml(code) + "</code></pre>" +
"</body>" +
"</html>";

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,15H5.5v-4.5H4V9h3V15zM13.5,13.5h-3v-1h2c0.55,0 1,-0.45 1,-1V10c0,-0.55 -0.45,-1 -1,-1H9v1.5h3v1h-2c-0.55,0 -1,0.45 -1,1V15h4.5V13.5zM19.5,14v-4c0,-0.55 -0.45,-1 -1,-1H15v1.5h3v1h-2v1h2v1h-3V15h3.5C19.05,15 19.5,14.55 19.5,14z"/>
</vector>

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_lines"
android:checkable="true"
android:icon="@drawable/twotone_123_24"
android:title="@string/title_legend_line_numbers"
app:showAsAction="always" />
<item
android:id="@+id/menu_sanitize"
android:checkable="true"

@ -2137,6 +2137,7 @@
<string name="title_legend_show_amp">Show AMP variant</string>
<string name="title_legend_show_full">Show original message</string>
<string name="title_legend_show_reformatted">Show reformatted message</string>
<string name="title_legend_line_numbers">Show line numbers</string>
<string name="title_legend_edit">Edit</string>
<string name="title_legend_default_color">Default color</string>
<string name="title_legend_close_hint">Close hint</string>

Loading…
Cancel
Save