vitepress-plugin-toolkit 0.4.0 → 0.6.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/dist/node/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Matcher } from "picomatch";
|
|
2
|
+
import { MarkdownEnv, Plugin, SiteConfig } from "vitepress";
|
|
2
3
|
import MarkdownIt from "markdown-it";
|
|
3
4
|
import { RenderRule } from "markdown-it/lib/renderer.mjs";
|
|
4
|
-
import { MarkdownEnv, Plugin, SiteConfig } from "vitepress";
|
|
5
5
|
|
|
6
6
|
//#region src/shared/link.d.ts
|
|
7
7
|
/**
|
|
@@ -126,6 +126,58 @@ interface SizeOptions {
|
|
|
126
126
|
ratio?: number | string;
|
|
127
127
|
}
|
|
128
128
|
//#endregion
|
|
129
|
+
//#region src/node/markdown/clean-markdown-env.d.ts
|
|
130
|
+
/**
|
|
131
|
+
* Clean Markdown Environment
|
|
132
|
+
*
|
|
133
|
+
* 清理后的 Markdown 环境
|
|
134
|
+
*/
|
|
135
|
+
interface CleanMarkdownEnv extends MarkdownEnv {
|
|
136
|
+
/**
|
|
137
|
+
* References
|
|
138
|
+
*
|
|
139
|
+
* 引用链接
|
|
140
|
+
*/
|
|
141
|
+
references?: unknown;
|
|
142
|
+
/**
|
|
143
|
+
* Abbreviations
|
|
144
|
+
*
|
|
145
|
+
* 缩写词
|
|
146
|
+
*/
|
|
147
|
+
abbreviations?: unknown;
|
|
148
|
+
/**
|
|
149
|
+
* Annotations
|
|
150
|
+
*
|
|
151
|
+
* 注释
|
|
152
|
+
*/
|
|
153
|
+
annotations?: unknown;
|
|
154
|
+
}
|
|
155
|
+
declare const WHITE_KEYS_LIST: readonly ["cleanUrls", "path", "realPath", "relativePath", "localeIndex", "references", "abbreviations", "annotations"];
|
|
156
|
+
type WhiteKeysListUnion = (typeof WHITE_KEYS_LIST)[number];
|
|
157
|
+
/**
|
|
158
|
+
* Clean markdown environment for inline rendering.
|
|
159
|
+
*
|
|
160
|
+
* 清理 markdown 环境以用于行内渲染。
|
|
161
|
+
*
|
|
162
|
+
* When using `md.renderInline()` in custom renderers, some environment properties
|
|
163
|
+
* may cause issues. This function creates a clean environment object with only
|
|
164
|
+
* the necessary properties preserved.
|
|
165
|
+
*
|
|
166
|
+
* 在自定义渲染器中使用 `md.renderInline()` 时,某些环境属性可能会导致问题。
|
|
167
|
+
* 该函数创建一个只保留必要属性的干净环境对象。
|
|
168
|
+
*
|
|
169
|
+
* @param env - Markdown environment / Markdown 环境
|
|
170
|
+
* @param exclude - Keys to exclude / 要排除的键
|
|
171
|
+
* @returns Cleaned environment / 清理后的环境
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const cleanEnv = cleanMarkdownEnv(env)
|
|
176
|
+
* const rendered = md.renderInline(content, cleanEnv)
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function cleanMarkdownEnv(env: MarkdownEnv, exclude?: WhiteKeysListUnion[]): CleanMarkdownEnv;
|
|
180
|
+
//#endregion
|
|
129
181
|
//#region src/node/markdown/container.d.ts
|
|
130
182
|
/**
|
|
131
183
|
* Type for getting RenderRule parameters
|
|
@@ -309,7 +361,7 @@ declare const EXTENSION_AUDIOS: string[];
|
|
|
309
361
|
* @param exclude - Patterns to exclude, can be string or array / 要排除的模式,可以是字符串或数组
|
|
310
362
|
* @returns Matcher instance / 匹配器实例
|
|
311
363
|
*/
|
|
312
|
-
declare function createMatcher(include?: string | string[], exclude?: string | string[]): Matcher
|
|
364
|
+
declare function createMatcher(include?: string | string[], exclude?: string | string[]): Matcher;
|
|
313
365
|
/**
|
|
314
366
|
* Resolve include and exclude patterns into pattern and ignore arrays.
|
|
315
367
|
* Converts various pattern formats into a standardized format for matching.
|
|
@@ -716,4 +768,4 @@ declare function getVitepressConfig(): SiteConfig;
|
|
|
716
768
|
*/
|
|
717
769
|
declare function resolveRouteLink(url: string, env: MarkdownEnv): string;
|
|
718
770
|
//#endregion
|
|
719
|
-
export { BuiltinLocale, BuiltinLocales, ContainerOptions, EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, EmbedRuleBlockOptions, LogLevel, LogType, Logger, SizeOptions, URL_PROTOCOL_RE, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, createMatcher, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveMatcherPattern, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };
|
|
771
|
+
export { BuiltinLocale, BuiltinLocales, CleanMarkdownEnv, ContainerOptions, EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, EmbedRuleBlockOptions, LogLevel, LogType, Logger, SizeOptions, URL_PROTOCOL_RE, cleanMarkdownEnv, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, createMatcher, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveMatcherPattern, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };
|
package/dist/node/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import container from "markdown-it-container";
|
|
2
|
-
import { LRUCache, camelCase, deepMerge, isArray, isBoolean, isNull, isNumber, isPrimitive, isString, isUndefined, kebabCase, objectEntries, objectKeys, omit, slash, toArray, uniq } from "@pengzhanbo/utils";
|
|
2
|
+
import { LRUCache, camelCase, deepMerge, isArray, isBoolean, isNull, isNumber, isPrimitive, isString, isUndefined, kebabCase, objectEntries, objectKeys, omit, removeTrailingSlash, slash, toArray, uniq } from "@pengzhanbo/utils";
|
|
3
3
|
import ansis from "ansis";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import picomatch from "picomatch";
|
|
@@ -79,6 +79,48 @@ function isLinkWithProtocol(link) {
|
|
|
79
79
|
return URL_PROTOCOL_RE.test(link) || link.startsWith("//");
|
|
80
80
|
}
|
|
81
81
|
//#endregion
|
|
82
|
+
//#region src/node/markdown/clean-markdown-env.ts
|
|
83
|
+
const WHITE_KEYS_LIST = [
|
|
84
|
+
"cleanUrls",
|
|
85
|
+
"path",
|
|
86
|
+
"realPath",
|
|
87
|
+
"relativePath",
|
|
88
|
+
"localeIndex",
|
|
89
|
+
"references",
|
|
90
|
+
"abbreviations",
|
|
91
|
+
"annotations"
|
|
92
|
+
];
|
|
93
|
+
/**
|
|
94
|
+
* Clean markdown environment for inline rendering.
|
|
95
|
+
*
|
|
96
|
+
* 清理 markdown 环境以用于行内渲染。
|
|
97
|
+
*
|
|
98
|
+
* When using `md.renderInline()` in custom renderers, some environment properties
|
|
99
|
+
* may cause issues. This function creates a clean environment object with only
|
|
100
|
+
* the necessary properties preserved.
|
|
101
|
+
*
|
|
102
|
+
* 在自定义渲染器中使用 `md.renderInline()` 时,某些环境属性可能会导致问题。
|
|
103
|
+
* 该函数创建一个只保留必要属性的干净环境对象。
|
|
104
|
+
*
|
|
105
|
+
* @param env - Markdown environment / Markdown 环境
|
|
106
|
+
* @param exclude - Keys to exclude / 要排除的键
|
|
107
|
+
* @returns Cleaned environment / 清理后的环境
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const cleanEnv = cleanMarkdownEnv(env)
|
|
112
|
+
* const rendered = md.renderInline(content, cleanEnv)
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function cleanMarkdownEnv(env, exclude = []) {
|
|
116
|
+
const result = {};
|
|
117
|
+
for (const key of WHITE_KEYS_LIST) {
|
|
118
|
+
if (exclude.includes(key)) continue;
|
|
119
|
+
result[key] = env[key];
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
82
124
|
//#region src/node/utils/resolve-attrs.ts
|
|
83
125
|
/**
|
|
84
126
|
* Regular expression for matching attribute values
|
|
@@ -864,7 +906,7 @@ const indexRE = /(^|.*\/)index.md(.*)$/i;
|
|
|
864
906
|
function resolveRouteLink(url, env) {
|
|
865
907
|
if (isExternal(url)) return url;
|
|
866
908
|
const config = getVitepressConfig();
|
|
867
|
-
if (url.startsWith("/")) return slash(config.site.base + url);
|
|
909
|
+
if (url.startsWith("/")) return slash(removeTrailingSlash(config.site.base) + url);
|
|
868
910
|
if (url.startsWith("#")) return decodeURI(normalizeHash(url));
|
|
869
911
|
const { pathname, protocol } = new URL(url, "http://a.com");
|
|
870
912
|
if (!url.startsWith("#") && protocol.startsWith("http") && treatAsHtml(pathname)) {
|
|
@@ -895,4 +937,4 @@ function normalizeHash(str) {
|
|
|
895
937
|
return str ? encodeURI(`#${slugify(decodeURI(str).slice(1))}`) : "";
|
|
896
938
|
}
|
|
897
939
|
//#endregion
|
|
898
|
-
export { EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, URL_PROTOCOL_RE, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, createMatcher, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveMatcherPattern, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };
|
|
940
|
+
export { EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, URL_PROTOCOL_RE, cleanMarkdownEnv, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, createMatcher, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveMatcherPattern, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-plugin-toolkit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "Development toolkit for vitepress plugins",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|