Skip to content

Commit 22ebeda

Browse files
committed
feat: 添加内置代码高亮功能控制选项
1 parent a63a116 commit 22ebeda

7 files changed

Lines changed: 39 additions & 5 deletions

File tree

settings.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,30 @@ spec:
527527
label: 打赏二维码
528528
validation: "required"
529529
- $formkit: checkbox
530+
name: highlight_open
531+
id: highlight_open
532+
key: highlight_open
533+
label: 内置代码块高亮
534+
value: true
535+
help: 默认使用内置代码块高亮,如果你需要使用代码块高亮插件,请关闭此选项以避免冲突
536+
- $formkit: checkbox
537+
if: "$get(highlight_open).value == true"
530538
name: code_line
539+
id: code_line
540+
key: code_line
531541
label: 代码块增加行号
532542
value: true
533543
- $formkit: checkbox
544+
if: "$get(highlight_open).value == true"
545+
id: code_line
546+
key: code_line
534547
name: code_change_line
535548
label: 代码块自动换行
536549
value: false
537550
- $formkit: select
551+
if: "$get(highlight_open).value == true"
552+
id: code_pretty
553+
key: code_pretty
538554
name: code_pretty
539555
label: 文章代码高亮主题
540556
value: Dracula

src/module/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ export class Utils {
175175
*/
176176
@documentFunction()
177177
public registerHighlight() {
178+
// 检查是否启用了代码高亮功能
179+
// @ts-ignore
180+
if (typeof window.highlight_open !== "undefined" && !window.highlight_open) {
181+
return;
182+
}
183+
178184
const preElements = document.querySelectorAll("pre") as NodeListOf<HTMLElement>;
179185
preElements.forEach((preElement) => {
180186
preElement.classList.add("highlight-wrap");
@@ -229,6 +235,12 @@ export class Utils {
229235
*/
230236
@documentFunction()
231237
public registerCopyCode() {
238+
// 检查是否启用了代码高亮功能
239+
// @ts-ignore
240+
if (typeof window.highlight_open !== "undefined" && !window.highlight_open) {
241+
return;
242+
}
243+
232244
const codeElements = document.querySelectorAll("pre code");
233245
codeElements.forEach((codeElement) => {
234246
const copyElement = document.createElement("span");

templates/assets/dist/main-2.4.3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/page/categories-2.4.3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/page/index-2.4.3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/page/photos-2.4.3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/module/head/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010

1111
<!--/* 字体 */-->
1212
<th:block th:replace="~{module/head/fonts}" />
13-
13+
14+
<!--/* 内置代码高亮功能控制 */-->
15+
<script th:inline="javascript">
16+
window.highlight_open = /*[[${theme.config.post.highlight_open}]]*/ [];
17+
</script>
18+
1419
<!--/* 高亮代码样式 */-->
1520
<link
21+
th:if="${theme.config.post.highlight_open}"
1622
rel="stylesheet"
1723
th:href="@{/assets/dist/css/highlight-{code_pretty}-{version}.min.css(code_pretty=${theme.config.post.code_pretty},version=${theme.spec.version})}"
1824
type="text/css"

0 commit comments

Comments
 (0)