From 7dd017f208f5f572f079a78e38310bf4ab1bcbfe Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:36:44 +0800 Subject: [PATCH 1/4] feat(highlight): add an option to disable stripIndent --- lib/hexo/default_config.ts | 6 ++++-- lib/plugins/highlight/highlight.ts | 3 ++- lib/plugins/highlight/prism.ts | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index bea0921ddd..3c91f38c27 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -48,13 +48,15 @@ export = { language_attr: false, hljs: false, line_threshold: 0, - first_line_number: 'always1' + first_line_number: 'always1', + disable_strip_indent: false }, prismjs: { preprocess: true, line_number: true, tab_replace: '', - exclude_languages: [] + exclude_languages: [], + disable_strip_indent: false }, // Category & Tag default_category: 'uncategorized', diff --git a/lib/plugins/highlight/highlight.ts b/lib/plugins/highlight/highlight.ts index 04d507ec92..cc4fc80465 100644 --- a/lib/plugins/highlight/highlight.ts +++ b/lib/plugins/highlight/highlight.ts @@ -33,7 +33,8 @@ module.exports = function highlightFilter(this: Hexo, code: string, options: Opt languageAttr, mark: options.mark, tab: hljsCfg.tab_replace, - wrap: hljsCfg.wrap + wrap: hljsCfg.wrap, + disableStripIndent: hljsCfg.disable_strip_indent }; if (hljsCfg.first_line_number === 'inline') { if (typeof options.firstLineNumber !== 'undefined') { diff --git a/lib/plugins/highlight/prism.ts b/lib/plugins/highlight/prism.ts index 33304068d4..e32dda0ebd 100644 --- a/lib/plugins/highlight/prism.ts +++ b/lib/plugins/highlight/prism.ts @@ -15,7 +15,8 @@ module.exports = function(code, options) { lang: options.lang, lineNumber, mark: options.mark, - tab: prismjsCfg.tab_replace + tab: prismjsCfg.tab_replace, + disableStripIndent: prismjsCfg.disable_strip_indent }; if (!prismHighlight) prismHighlight = require('hexo-util').prismHighlight; From e2eea034715d6aff1e712f682c4be1fab8e746e6 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:06:26 +0800 Subject: [PATCH 2/4] feat(highlight): add an option to switch stripIndent --- lib/hexo/default_config.ts | 4 ++-- lib/plugins/highlight/highlight.ts | 2 +- lib/plugins/highlight/prism.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index 3c91f38c27..83fc7e35aa 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -49,14 +49,14 @@ export = { hljs: false, line_threshold: 0, first_line_number: 'always1', - disable_strip_indent: false + strip_indent: false }, prismjs: { preprocess: true, line_number: true, tab_replace: '', exclude_languages: [], - disable_strip_indent: false + strip_indent: false }, // Category & Tag default_category: 'uncategorized', diff --git a/lib/plugins/highlight/highlight.ts b/lib/plugins/highlight/highlight.ts index cc4fc80465..ddc79902f1 100644 --- a/lib/plugins/highlight/highlight.ts +++ b/lib/plugins/highlight/highlight.ts @@ -34,7 +34,7 @@ module.exports = function highlightFilter(this: Hexo, code: string, options: Opt mark: options.mark, tab: hljsCfg.tab_replace, wrap: hljsCfg.wrap, - disableStripIndent: hljsCfg.disable_strip_indent + stripIndent: hljsCfg.strip_indent }; if (hljsCfg.first_line_number === 'inline') { if (typeof options.firstLineNumber !== 'undefined') { diff --git a/lib/plugins/highlight/prism.ts b/lib/plugins/highlight/prism.ts index e32dda0ebd..55da21d02e 100644 --- a/lib/plugins/highlight/prism.ts +++ b/lib/plugins/highlight/prism.ts @@ -16,7 +16,7 @@ module.exports = function(code, options) { lineNumber, mark: options.mark, tab: prismjsCfg.tab_replace, - disableStripIndent: prismjsCfg.disable_strip_indent + stripIndent: prismjsCfg.strip_indent }; if (!prismHighlight) prismHighlight = require('hexo-util').prismHighlight; From 9469cff487c5eb400641cccb262a3f6e7b02eecb Mon Sep 17 00:00:00 2001 From: Uiolee <22849383+uiolee@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:22:26 +0800 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: yoshinorin --- lib/hexo/default_config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index 83fc7e35aa..6d1ede870c 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -49,14 +49,14 @@ export = { hljs: false, line_threshold: 0, first_line_number: 'always1', - strip_indent: false + strip_indent: true }, prismjs: { preprocess: true, line_number: true, tab_replace: '', exclude_languages: [], - strip_indent: false + strip_indent: true }, // Category & Tag default_category: 'uncategorized', From a211ab0437d842035ef10ad964f2cd6057b18a15 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:46:08 +0800 Subject: [PATCH 4/4] update hexo-util to 330 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6bec8d9b1..2255dd4cc7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "hexo-fs": "^4.1.1", "hexo-i18n": "^2.0.0", "hexo-log": "^4.0.1", - "hexo-util": "^3.0.1", + "hexo-util": "^3.3.0", "js-yaml": "^4.1.0", "js-yaml-js-types": "^1.0.0", "micromatch": "^4.0.4",