hexo-renderer-markdown-exit 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +5 -0
- package/bun.lock +125 -1
- package/dist/index.js +1 -60304
- package/package.json +8 -2
- package/readme.md +2 -1
- package/src/index.ts +11 -2
- package/src/renderer.ts +27 -33
- package/types/types.d.ts +1 -0
- package/vite.config.ts +20 -0
- package/dist/renderer.js +0 -94
- package/dist/types.js +0 -1
- package/justfile +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hexo-renderer-markdown-exit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A Hexo renderer plugin using markdown-exit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -9,11 +9,16 @@
|
|
|
9
9
|
"markdown",
|
|
10
10
|
"markdown-exit"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "vite build",
|
|
14
|
+
"fmt": "bunx biome check --write ."
|
|
15
|
+
},
|
|
12
16
|
"author": "GnixAIj",
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"@mdit/plugin-tab": "^0.23.0",
|
|
16
20
|
"markdown-exit": "^1.0.0-beta.6",
|
|
21
|
+
"markdown-exit-shiki": "^0.1.0",
|
|
17
22
|
"markdown-it-abbr": "^2.0.0",
|
|
18
23
|
"markdown-it-anchor": "^9.2.0",
|
|
19
24
|
"markdown-it-emoji": "^3.0.0",
|
|
@@ -32,6 +37,7 @@
|
|
|
32
37
|
"bun-types": "^1.1.18",
|
|
33
38
|
"hexo": "^7.0.0",
|
|
34
39
|
"hexo-util": "^4.0.0",
|
|
35
|
-
"typescript": "^5.0.0"
|
|
40
|
+
"typescript": "^5.0.0",
|
|
41
|
+
"vite": "^7.2.7"
|
|
36
42
|
}
|
|
37
43
|
}
|
package/readme.md
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { StoreFunction, StoreFunctionData } from "hexo/dist/extend/renderer";
|
|
2
2
|
import { MarkdownRenderer } from "./renderer";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
let rendererInstance: MarkdownRenderer | null = null;
|
|
5
5
|
|
|
6
|
+
function getRenderer(): MarkdownRenderer {
|
|
7
|
+
if (!rendererInstance) {
|
|
8
|
+
rendererInstance = new MarkdownRenderer(hexo);
|
|
9
|
+
}
|
|
10
|
+
return rendererInstance;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Hexo在执行`clean`命令删除`public`目录时也会加载各个插件,包括本插件中渲染器的注册
|
|
14
|
+
// 所以把渲染器的实例化延迟到真正需要渲染时再进行,避免在`clean`命令时进行不必要的初始化操作
|
|
6
15
|
const render: StoreFunction = async (data: StoreFunctionData): Promise<string> =>
|
|
7
|
-
await
|
|
16
|
+
await getRenderer().render(data);
|
|
8
17
|
|
|
9
18
|
render.disableNunjucks = Boolean(hexo.config.markdown_exit.disableNunjucks);
|
|
10
19
|
|
package/src/renderer.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { tab } from "@mdit/plugin-tab";
|
|
|
3
3
|
import type Hexo from "hexo";
|
|
4
4
|
import type { StoreFunctionData } from "hexo/dist/extend/renderer";
|
|
5
5
|
import { createMarkdownExit, type MarkdownExit } from "markdown-exit";
|
|
6
|
+
import code from "markdown-exit-shiki";
|
|
6
7
|
import abbr from "markdown-it-abbr";
|
|
7
8
|
import anchor from "markdown-it-anchor";
|
|
8
9
|
import { full as emoji } from "markdown-it-emoji";
|
|
@@ -13,6 +14,7 @@ import mathjax3Pro from "markdown-it-mathjax3-pro";
|
|
|
13
14
|
import sub from "markdown-it-sub";
|
|
14
15
|
import sup from "markdown-it-sup";
|
|
15
16
|
import taskLists from "markdown-it-task-lists";
|
|
17
|
+
|
|
16
18
|
import type { MarkdownExitConfig, PluginConfig } from "../types/types";
|
|
17
19
|
|
|
18
20
|
export class MarkdownRenderer {
|
|
@@ -32,6 +34,11 @@ export class MarkdownRenderer {
|
|
|
32
34
|
typographer: true,
|
|
33
35
|
xhtmlOut: false,
|
|
34
36
|
},
|
|
37
|
+
code_options: {
|
|
38
|
+
themes: {
|
|
39
|
+
light: "catppuccin-latte",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
35
42
|
...hexo.config.markdown_exit,
|
|
36
43
|
};
|
|
37
44
|
|
|
@@ -40,6 +47,7 @@ export class MarkdownRenderer {
|
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
private initPlugins() {
|
|
50
|
+
console.time("MarkdownExit: Load Default Plugins");
|
|
43
51
|
if (this.config.defaultPlugins !== false) {
|
|
44
52
|
this.md
|
|
45
53
|
// @ts-expect-error: MarkdownExit is compatible with MarkdownIt at runtime but types mismatch
|
|
@@ -51,6 +59,7 @@ export class MarkdownRenderer {
|
|
|
51
59
|
.use(abbr)
|
|
52
60
|
.use(ins)
|
|
53
61
|
.use(taskLists)
|
|
62
|
+
.use(code, this.config.code_options)
|
|
54
63
|
// @ts-expect-error: MarkdownExit is compatible with MarkdownIt at runtime but types mismatch
|
|
55
64
|
.use(tab)
|
|
56
65
|
// @ts-expect-error: MarkdownExit is compatible with MarkdownIt at runtime but types mismatch
|
|
@@ -58,46 +67,31 @@ export class MarkdownRenderer {
|
|
|
58
67
|
// @ts-expect-error: MarkdownExit is compatible with MarkdownIt at runtime but types mismatch
|
|
59
68
|
.use(mathjax3Pro);
|
|
60
69
|
}
|
|
61
|
-
|
|
70
|
+
console.timeEnd("MarkdownExit: Load Default Plugins");
|
|
71
|
+
console.time("MarkdownExit: Load User Plugins");
|
|
62
72
|
this.loadUserPlugins();
|
|
73
|
+
console.timeEnd("MarkdownExit: Load User Plugins");
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
private loadUserPlugins() {
|
|
66
77
|
const plugins: PluginConfig[] = this.config.plugins || [];
|
|
67
|
-
const baseDir = this.hexo.base_dir;
|
|
68
|
-
|
|
69
|
-
if (!Array.isArray(plugins)) {
|
|
70
|
-
console.warn("Plugins configuration is not an array. Skipping plugin loading.");
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const userNodeModules = path.join(baseDir, "node_modules");
|
|
75
|
-
|
|
76
78
|
for (const pluginConfig of plugins) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
const isString = typeof pluginConfig === "string";
|
|
80
|
+
const pluginName = isString ? pluginConfig : pluginConfig.name;
|
|
81
|
+
const pluginOptions = isString ? {} : pluginConfig.options || {};
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.md.use(pluginFn, pluginOptions);
|
|
93
|
-
if (process.env.DEBUG) {
|
|
94
|
-
console.log(`✅ Successfully loaded plugin: ${pluginName}`);
|
|
95
|
-
}
|
|
96
|
-
} catch (e) {
|
|
97
|
-
console.warn(`⚠️ Failed to load plugin: ${pluginName}`);
|
|
98
|
-
if (process.env.DEBUG) {
|
|
99
|
-
console.warn(` Error: ${e}`);
|
|
100
|
-
}
|
|
83
|
+
try {
|
|
84
|
+
const pluginPath = path.join(this.hexo.base_dir, "node_modules", pluginName);
|
|
85
|
+
const plugin = require(pluginPath);
|
|
86
|
+
const pluginFn = plugin.default || plugin;
|
|
87
|
+
this.md.use(pluginFn, pluginOptions);
|
|
88
|
+
if (process.env.DEBUG) {
|
|
89
|
+
console.log(`✅ Successfully loaded plugin: ${pluginName}`);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.warn(`⚠️ Failed to load plugin: ${pluginName}`);
|
|
93
|
+
if (process.env.DEBUG) {
|
|
94
|
+
console.warn(` Error: ${e}`);
|
|
101
95
|
}
|
|
102
96
|
}
|
|
103
97
|
}
|
package/types/types.d.ts
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import pkg from "./package.json";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
build: {
|
|
6
|
+
lib: {
|
|
7
|
+
entry: "./src/index.ts",
|
|
8
|
+
name: "hexo-renderer-markdown-exit",
|
|
9
|
+
formats: ["cjs"],
|
|
10
|
+
fileName: () => "index.js",
|
|
11
|
+
},
|
|
12
|
+
rollupOptions: {
|
|
13
|
+
external: [
|
|
14
|
+
...Object.keys(pkg.dependencies || {}),
|
|
15
|
+
/^node:/,
|
|
16
|
+
"hexo",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
package/dist/renderer.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || ((mod) => (mod && mod.__esModule) ? mod : { "default": mod });
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.renderer = void 0;
|
|
5
|
-
const markdown_exit_1 = require("markdown-exit");
|
|
6
|
-
const markdown_it_emoji_1 = require("markdown-it-emoji");
|
|
7
|
-
const markdown_it_footnote_1 = __importDefault(require("markdown-it-footnote"));
|
|
8
|
-
const markdown_it_mark_1 = __importDefault(require("markdown-it-mark"));
|
|
9
|
-
const markdown_it_mathjax3_pro_1 = __importDefault(require("markdown-it-mathjax3-pro"));
|
|
10
|
-
const markdown_it_sub_1 = __importDefault(require("markdown-it-sub"));
|
|
11
|
-
const markdown_it_sup_1 = __importDefault(require("markdown-it-sup"));
|
|
12
|
-
const markdown_it_task_lists_1 = __importDefault(require("markdown-it-task-lists"));
|
|
13
|
-
const markdown_it_abbr_1 = __importDefault(require("markdown-it-abbr"));
|
|
14
|
-
const markdown_it_ins_1 = __importDefault(require("markdown-it-ins"));
|
|
15
|
-
let cachedMd;
|
|
16
|
-
let cachedConfig;
|
|
17
|
-
// Hexo 7.x
|
|
18
|
-
const renderer = async function (data, options) {
|
|
19
|
-
if (!data.text) {
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
22
|
-
const hexoConfig = this.config;
|
|
23
|
-
const config = { ...hexoConfig.markdown_exit, ...options };
|
|
24
|
-
const configStr = JSON.stringify(config);
|
|
25
|
-
if (cachedMd && cachedConfig === configStr) {
|
|
26
|
-
return cachedMd.renderAsync(data.text);
|
|
27
|
-
}
|
|
28
|
-
const markdownExitConfig = {
|
|
29
|
-
breaks: true,
|
|
30
|
-
html: true,
|
|
31
|
-
langPrefix: "language-",
|
|
32
|
-
linkify: true,
|
|
33
|
-
quotes: "“”‘’",
|
|
34
|
-
typographer: true,
|
|
35
|
-
xhtmlOut: false,
|
|
36
|
-
...hexoConfig.markdown_exit?.render_options
|
|
37
|
-
};
|
|
38
|
-
const md = (0, markdown_exit_1.createMarkdownExit)(markdownExitConfig);
|
|
39
|
-
if (config.defaultPlugins !== false) {
|
|
40
|
-
md.use(markdown_it_emoji_1.full)
|
|
41
|
-
.use(markdown_it_footnote_1.default)
|
|
42
|
-
.use(markdown_it_mark_1.default)
|
|
43
|
-
.use(markdown_it_sub_1.default)
|
|
44
|
-
.use(markdown_it_sup_1.default)
|
|
45
|
-
.use(markdown_it_abbr_1.default)
|
|
46
|
-
.use(markdown_it_ins_1.default)
|
|
47
|
-
.use(markdown_it_task_lists_1.default)
|
|
48
|
-
.use(markdown_it_mathjax3_pro_1.default);
|
|
49
|
-
}
|
|
50
|
-
// Register plugins from the user's configuration
|
|
51
|
-
loadMarkdownItPlugins(md, config.plugins || [], this.base_dir);
|
|
52
|
-
cachedMd = md;
|
|
53
|
-
cachedConfig = configStr;
|
|
54
|
-
return md.renderAsync(data.text);
|
|
55
|
-
};
|
|
56
|
-
exports.renderer = renderer;
|
|
57
|
-
function loadMarkdownItPlugins(md, plugins, baseDir) {
|
|
58
|
-
// 确保 plugins 是一个数组
|
|
59
|
-
if (!Array.isArray(plugins)) {
|
|
60
|
-
console.warn('Plugins configuration is not an array. Skipping plugin loading.');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// 遍历插件配置
|
|
64
|
-
for (const pluginConfig of plugins) {
|
|
65
|
-
let pluginName;
|
|
66
|
-
let pluginOptions = {};
|
|
67
|
-
if (typeof pluginConfig === 'string') {
|
|
68
|
-
pluginName = pluginConfig;
|
|
69
|
-
}
|
|
70
|
-
else if (typeof pluginConfig === 'object' && pluginConfig.name) {
|
|
71
|
-
pluginName = pluginConfig.name;
|
|
72
|
-
pluginOptions = pluginConfig.options || {};
|
|
73
|
-
}
|
|
74
|
-
if (pluginName) {
|
|
75
|
-
try {
|
|
76
|
-
let plugin;
|
|
77
|
-
try {
|
|
78
|
-
const pluginPath = require.resolve(pluginName, { paths: [baseDir] });
|
|
79
|
-
plugin = require(pluginPath);
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
plugin = require(pluginName);
|
|
83
|
-
}
|
|
84
|
-
const pluginFn = plugin.default || plugin;
|
|
85
|
-
md.use(pluginFn, pluginOptions);
|
|
86
|
-
console.log(`✅ Successfully loaded plugin: ${pluginName}`);
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
console.warn(`⚠️ Failed to load plugin: ${pluginName}`);
|
|
90
|
-
console.warn(` Please install it in your Hexo project: npm install ${pluginName}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/justfile
DELETED