diff options
author | Andrew Dolgov <[email protected]> | 2021-03-05 11:56:15 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-03-05 11:56:15 +0300 |
commit | f1e47f5f3283466b3e48b8da305e1d43f73118b5 (patch) | |
tree | f44665025ab74c7bb8a81e25554e1f4703873adb | |
parent | 1077abdddae0e9068820c5630525b94c0e173831 (diff) |
deal with inline code elements properly
-rw-r--r-- | init.js | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -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); }); }); }); |