summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-05 11:56:15 +0300
committerAndrew Dolgov <[email protected]>2021-03-05 11:56:15 +0300
commitf1e47f5f3283466b3e48b8da305e1d43f73118b5 (patch)
treef44665025ab74c7bb8a81e25554e1f4703873adb
parent1077abdddae0e9068820c5630525b94c0e173831 (diff)
deal with inline code elements properly
-rw-r--r--init.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/init.js b/init.js
index a2e2572..7b85086 100644
--- a/init.js
+++ b/init.js
@@ -1,24 +1,23 @@
+/* global require, PluginHost, hljs */
+
require(['dojo/_base/kernel', 'dojo/ready', 'dojo/request/script'], function (dojo, ready, script) {
ready(function() {
+ function highlight_all(row, hljs) {
+ row.querySelectorAll("code").forEach((elem) => {
+ hljs.highlightBlock(elem);
+ if (!elem.closest('pre')) elem.setStyle({display: 'inline', padding: 0});
+ });
+ }
+
script.get("plugins.local/highlightjs/highlight.pack.js",
{checkString: 'hljs'}).then(() => {
- console.log('hljs loaded', hljs)
-
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
- row.querySelectorAll("code").forEach((elem) => {
- console.log('about to highlight', elem);
-
- hljs.highlightBlock(elem);
- });
+ highlight_all(row, hljs);
});
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, function(row) {
- row.querySelectorAll("code").forEach((elem) => {
- console.log('about to highlight', elem);
-
- hljs.highlightBlock(elem);
- });
+ highlight_all(row, hljs);
});
});
});