make prism optional

This commit is contained in:
ed
2021-11-04 03:10:13 +01:00
parent 3899c7ad56
commit cb7674b091
7 changed files with 29 additions and 9 deletions

View File

@@ -2281,6 +2281,9 @@ class HttpCli(object):
j2a["doc"] = doc
if not self.conn.hsrv.prism:
j2a["no_prism"] = True
for d in dirs:
d["name"] += "/"
@@ -2289,7 +2292,7 @@ class HttpCli(object):
j2a["files"] = dirs + files
j2a["logues"] = logues
j2a["taglist"] = taglist
j2a["txt_ext"] = self.args.textfiles.replace(',', ' ')
j2a["txt_ext"] = self.args.textfiles.replace(",", " ")
if "mth" in vn.flags:
j2a["def_hcols"] = vn.flags["mth"].split(",")

View File

@@ -76,6 +76,7 @@ class HttpSrv(object):
x: env.get_template(x + ".html")
for x in ["splash", "browser", "browser2", "msg", "md", "mde"]
}
self.prism = os.path.exists(os.path.join(E.mod, "web", "deps", "prism.js.gz"))
cert_path = os.path.join(E.cfg, "cert.pem")
if bos.path.exists(cert_path):

View File

@@ -142,6 +142,7 @@
have_unpost = {{ have_unpost|tojson }},
have_zip = {{ have_zip|tojson }},
txt_ext = "{{ txt_ext }}",
{% if no_prism %}no_prism = 1,{% endif %}
readme = {{ readme|tojson }};
document.documentElement.setAttribute("class", localStorage.lightmode == 1 ? "light" : "dark");

View File

@@ -2336,6 +2336,9 @@ var showfile = (function () {
em = [r.sname(window.location.search), window.location.hash, em.textContent];
r.setstyle = function () {
if (window['no_prism'])
return;
qsr('#prism_css');
var el = mknod('link');
el.rel = 'stylesheet';
@@ -2438,11 +2441,13 @@ var showfile = (function () {
else {
el.textContent = txt;
el.innerHTML = '<code>' + el.innerHTML + '</code>';
el.setAttribute('class', 'prism linkable-line-numbers line-numbers language-' + lang);
if (!defer)
fun(el.firstChild);
else
import_js('/.cpr/deps/prism.js', function () { fun(); });
if (!window['no_prism']) {
el.setAttribute('class', 'prism linkable-line-numbers line-numbers language-' + lang);
if (!defer)
fun(el.firstChild);
else
import_js('/.cpr/deps/prism.js', function () { fun(); });
}
}
wr.appendChild(el);