From 11e64c5804b696f170b9d5d881befbabc4a4e85c Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Sun, 5 Jan 2025 15:05:17 +0800 Subject: mv highlight fuction into another domain In the old version, to make highlight usable forever, I decided to use own local version but not cdn of highlight.js website, and write my config js to use it and line-numbers/copy. However, it's hard to upgrade highlight.js. So I move all highlight function into spercific domain, it's easy to change configs or upgrade the hole highlight.js. Besides, it benifits to other sites, because I want to use them now only in blogs, but also in cgit code show pages. --- code/cpppp.html | 2 +- code/highlight.html | 2 +- code/index.html | 2 +- code/linux/aliyun_cloud.html | 2 +- code/linux/gitserver.html | 2 +- code/linux/httpmyserver.html | 2 +- code/linux/keymap.html | 2 +- code/linux/vim.html | 2 +- code/projects/lcm_compile.html | 2 +- common/CSS/highlight.css | 83 ------------------------------------------ common/js/myhighlight.js | 78 --------------------------------------- courseNotes/parallel.html | 3 +- 12 files changed, 10 insertions(+), 172 deletions(-) delete mode 100644 common/CSS/highlight.css delete mode 100644 common/js/myhighlight.js diff --git a/code/cpppp.html b/code/cpppp.html index ee44972..2bfb80e 100644 --- a/code/cpppp.html +++ b/code/cpppp.html @@ -7,7 +7,7 @@ cpppp快速基础 - \n + diff --git a/code/highlight.html b/code/highlight.html index e2dee0d..1874af8 100644 --- a/code/highlight.html +++ b/code/highlight.html @@ -5,7 +5,7 @@ 我的代码块 - + diff --git a/code/index.html b/code/index.html index ec6ecce..0550e98 100644 --- a/code/index.html +++ b/code/index.html @@ -7,7 +7,7 @@ 我的实用代码 - + diff --git a/code/linux/aliyun_cloud.html b/code/linux/aliyun_cloud.html index bab99aa..f430bae 100644 --- a/code/linux/aliyun_cloud.html +++ b/code/linux/aliyun_cloud.html @@ -7,7 +7,7 @@ 我的免费云服 - + diff --git a/code/linux/gitserver.html b/code/linux/gitserver.html index d0badaf..8c97999 100644 --- a/code/linux/gitserver.html +++ b/code/linux/gitserver.html @@ -7,7 +7,7 @@ 自己的 git 托管 - + diff --git a/code/linux/httpmyserver.html b/code/linux/httpmyserver.html index b4f1337..d1e14a7 100644 --- a/code/linux/httpmyserver.html +++ b/code/linux/httpmyserver.html @@ -7,7 +7,7 @@ http浏览服务器文件 - + diff --git a/code/linux/keymap.html b/code/linux/keymap.html index 97f64d6..a21a19a 100644 --- a/code/linux/keymap.html +++ b/code/linux/keymap.html @@ -6,7 +6,7 @@ 键盘映射 - + diff --git a/code/linux/vim.html b/code/linux/vim.html index badf5d5..75e0075 100644 --- a/code/linux/vim.html +++ b/code/linux/vim.html @@ -7,7 +7,7 @@ vim学习与我的配置 - + diff --git a/code/projects/lcm_compile.html b/code/projects/lcm_compile.html index dbc8109..d889b58 100644 --- a/code/projects/lcm_compile.html +++ b/code/projects/lcm_compile.html @@ -7,7 +7,7 @@ LCM 交叉编译 - + diff --git a/common/CSS/highlight.css b/common/CSS/highlight.css deleted file mode 100644 index 14b71ed..0000000 --- a/common/CSS/highlight.css +++ /dev/null @@ -1,83 +0,0 @@ -/* for block of numbers */ -pre code td.hljs-ln-numbers { - color: #9c9c9c; - border-right: 0.5px solid #9c9c9c; - vertical-align: top; - padding-left: 0.5rem; - padding-right: 0.8rem; - border: none; - text-align: right; -} - -/* for block of code */ -pre code td.hljs-ln-code { - /* padding-left: 1rem; */ - border: none; -} - -pre { - position: relative; -} - -pre .btn { - display: none; - position: absolute; - top: 0; - right: 0; - background: #333; - color: #f5f5f5; - border: none; - outline: none !important; -} - -pre .btn:hover { - color: #fff -} - -pre:hover .btn { - display: block; -} - -pre .btn-tip { - display: none; - position: absolute; - top: 0px; - right: 0; - z-index: 9; - padding: 6px 12px; - background: #333; - color: #f5f5f5; - border: none; - border-radius: 4px; -} - -.btn { - display: inline-block; - padding: 6px 12px; - margin-bottom: 0; - font-size: 14px; - font-weight: 400; - line-height: 1.42857143; - text-align: center; - white-space: nowrap; - vertical-align: middle; - -ms-touch-action: manipulation; - touch-action: manipulation; - cursor: pointer; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - background-image: none; - border: 1px solid transparent; - border-radius: 4px; -} - -/* 代码复制时全选但不能被看到 - * 该功能是不道德的,用户想要怎么复制是人家的权利 - * 即使是自己用起来也经常只需要复制一段 - * 所以还是让用户自由复制吧 - */ -/* code ::selection { - background-color: rgba(0, 0, 0, 0); -} */ \ No newline at end of file diff --git a/common/js/myhighlight.js b/common/js/myhighlight.js deleted file mode 100644 index 826c14d..0000000 --- a/common/js/myhighlight.js +++ /dev/null @@ -1,78 +0,0 @@ -// 代码高亮、加行号、加一键复制功能 - -// 加js的函数 -function addScript(url, async = true) { - //默认先到先得地加载 - const script = document.createElement('script'); - script.src = url; - script.async = async; - document.head.appendChild(script); -} - -// 加link的函数 -function addLink(href, rel = 'stylesheet') { - // 默认为stylesheet - const link = document.createElement('link'); - link.rel = rel; - link.href = href; - document.head.appendChild(link); -} - -// 此处是各个插件 -// 首先放置最高的jQuery备用 -// 而后是highlight.min.js高亮代码 -// 再加行号 -// 最后cliploard供一键复制使用 -var url = ["https://www.qin-juan-ge-zhu.top/common/js/jQuery.js", "https://www.qin-juan-ge-zhu.top/common/highlight/highlight.min.js", "https://www.qin-juan-ge-zhu.top/common/highlight/plugs/highlightjs-line-numbers.js", "https://www.qin-juan-ge-zhu.top/common/highlight/plugs/clipboard.min.js"] - -for (let i in url) { - // 要求必须按顺序加载 - addScript(url[i], false); -} - -// 加载高亮所需特殊css -addLink("https://www.qin-juan-ge-zhu.top/common/CSS/highlight.css"); - -// 此处负责随机选择一个代码高亮style的css并加载 -// 数组内是现highlight.js所有插件名称,共计75个 -const styles = ["a11y-dark.min.css", "a11y-light.min.css", "agate.min.css", "androidstudio.min.css", "an-old-hope.min.css", "arduino-light.min.css", "arta.min.css", "ascetic.min.css", "atom-one-dark.min.css", "atom-one-dark-reasonable.min.css", "atom-one-light.min.css", "base16", "brown-paper.min.css", "brown-papersq.png", "codepen-embed.min.css", "color-brewer.min.css", "dark.min.css", "default.min.css", "devibeans.min.css", "docco.min.css", "far.min.css", "felipec.min.css", "foundation.min.css", "github-dark-dimmed.min.css", "github-dark.min.css", "github.min.css", "gml.min.css", "googlecode.min.css", "gradient-dark.min.css", "gradient-light.min.css", "grayscale.min.css", "hybrid.min.css", "idea.min.css", "intellij-light.min.css", "ir-black.min.css", "isbl-editor-dark.min.css", "isbl-editor-light.min.css", "kimbie-dark.min.css", "kimbie-light.min.css", "lightfair.min.css", "lioshi.min.css", "magula.min.css", "mono-blue.min.css", "monokai.min.css", "monokai-sublime.min.css", "night-owl.min.css", "nnfx-dark.min.css", "nnfx-light.min.css", "nord.min.css", "obsidian.min.css", "panda-syntax-dark.min.css", "panda-syntax-light.min.css", "paraiso-dark.min.css", "paraiso-light.min.css", "pojoaque.jpg", "pojoaque.min.css", "purebasic.min.css", "qtcreator-dark.min.css", "qtcreator-light.min.css", "rainbow.min.css", "routeros.min.css", "school-book.min.css", "shades-of-purple.min.css", "srcery.min.css", "stackoverflow-dark.min.css", "stackoverflow-light.min.css", "sunburst.min.css", "tokyo-night-dark.min.css", "tokyo-night-light.min.css", "tomorrow-night-blue.min.css", "tomorrow-night-bright.min.css", "vs2015.min.css", "vs.min.css", "xcode.min.css", "xt256.min.css"]; - -const href = "https://www.qin-juan-ge-zhu.top/common/highlight/styles/" + styles[~~(Math.random() * styles.length)]; -addLink(href); - -// 以下代码负责使用上述模块,因而必须在html文档整体完成之后加载 -onload = () => { - // 导出的源码由
……
包裹,符合highlight.min.js要求 - // 需要在code之前加入复制按钮,要求点击之后显示已复制 - var allpre = document.getElementsByTagName("pre"); - for (i = 0; i < allpre.length; i++) { - var onepre = document.getElementsByTagName("pre")[i]; - var mycode = document.getElementsByTagName("pre")[i].innerHTML; - onepre.innerHTML = '
已复制!
' + mycode; - }; - - // 这两行负责加载代码高亮并为代码添加行号 - hljs.initHighlightingOnLoad(); - hljs.initLineNumbersOnLoad(); - - // 循环为pre标签加id - $("pre").each(function () { - $(this).attr('id', "pre" + $(this).index()); - var btns = $(this).find("button"); - $(btns).attr('data-clipboard-target', "#pre" + $(this).index()) - }); - var clipboard = new ClipboardJS('.btn'); - - // 是否成功复制 - clipboard.on('success', function (e) { - $(".btn").each(function () { - var btntip = $(this).find("span.btn-tip"); - $(btntip).css("display", "block").delay(1000).fadeOut(200); - }); - console.log(e); - }); - - clipboard.on('error', function (e) { - console.log(e); - }); -}; \ No newline at end of file diff --git a/courseNotes/parallel.html b/courseNotes/parallel.html index 163bd24..ebd09d4 100644 --- a/courseNotes/parallel.html +++ b/courseNotes/parallel.html @@ -7,9 +7,8 @@ 并行计算大法好 - + -