@kernelift/markdown 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -101,8 +101,8 @@ const handleCopy = (code: string) => {
101
101
  </script>
102
102
 
103
103
  <template>
104
- <MdRender
105
- v-model="content"
104
+ <MdRender
105
+ v-model="content"
106
106
  :code-max-height="15"
107
107
  copy-text="复制"
108
108
  expand-text="查看更多"
@@ -123,19 +123,16 @@ import type { MarkdownItOptions } from '@kernelift/markdown';
123
123
  const content = ref('# Hello World');
124
124
 
125
125
  const options: MarkdownItOptions = {
126
- html: false, // 禁用 HTML 标签
127
- linkify: true, // 自动识别链接
128
- breaks: true, // 启用换行符
129
- typographer: true, // 启用排版优化
130
- table: true // 启用表格
126
+ html: false, // 禁用 HTML 标签
127
+ linkify: true, // 自动识别链接
128
+ breaks: true, // 启用换行符
129
+ typographer: true, // 启用排版优化
130
+ table: true // 启用表格
131
131
  };
132
132
  </script>
133
133
 
134
134
  <template>
135
- <MdRender
136
- v-model="content"
137
- :options="options"
138
- />
135
+ <MdRender v-model="content" :options="options" />
139
136
  </template>
140
137
  ```
141
138
 
@@ -153,10 +150,41 @@ const plugins = [markdownItEmoji];
153
150
  </script>
154
151
 
155
152
  <template>
156
- <MdRender
157
- v-model="content"
158
- :plugins="plugins"
159
- />
153
+ <MdRender v-model="content" :plugins="plugins" />
154
+ </template>
155
+ ```
156
+
157
+ ### Markdown 实例后处理
158
+
159
+ 使用 `afterRender` 回调可以在 MarkdownIt 实例创建后进行额外的配置,例如添加自定义渲染规则。
160
+
161
+ ```vue
162
+ <script setup lang="ts">
163
+ import { ref } from 'vue';
164
+ import { MdRender } from '@kernelift/markdown';
165
+ import type MarkdownIt from 'markdown-it';
166
+
167
+ const content = ref('Hello World');
168
+
169
+ const handleAfterRender = (md: MarkdownIt) => {
170
+ // 添加自定义规则
171
+ const defaultRender =
172
+ md.renderer.rules.text ||
173
+ function (tokens, idx, options, env, self) {
174
+ return self.renderToken(tokens, idx, options);
175
+ };
176
+
177
+ md.renderer.rules.text = function (tokens, idx, options, env, self) {
178
+ // 自定义文本渲染逻辑
179
+ return defaultRender(tokens, idx, options, env, self);
180
+ };
181
+
182
+ console.log('MarkdownIt 实例已配置');
183
+ };
184
+ </script>
185
+
186
+ <template>
187
+ <MdRender v-model="content" :after-render="handleAfterRender" />
160
188
  </template>
161
189
  ```
162
190
 
@@ -191,10 +219,7 @@ const parseInline = () => {
191
219
  <button @click="getRenderedHtml">获取渲染 HTML</button>
192
220
  <button @click="parseInline">解析内联文本</button>
193
221
  </div>
194
- <MdRender
195
- ref="renderRef"
196
- v-model="content"
197
- />
222
+ <MdRender ref="renderRef" v-model="content" />
198
223
  </div>
199
224
  </template>
200
225
  ```
@@ -212,85 +237,55 @@ const isDark = ref(true);
212
237
 
213
238
  <template>
214
239
  <div :class="{ dark: isDark }">
215
- <MdRender
216
- v-model="content"
217
- :class="{ dark: isDark }"
218
- />
240
+ <MdRender v-model="content" :class="{ dark: isDark }" />
219
241
  </div>
220
242
  </template>
221
243
  ```
222
244
 
223
- ### 使用简化版组件
224
-
225
- ```vue
226
- <script setup lang="ts">
227
- import { ref } from 'vue';
228
- import { MdRenderSimple } from '@kernelift/markdown';
229
-
230
- const content = ref('# Hello World');
231
- </script>
232
-
233
- <template>
234
- <MdRenderSimple v-model="content" />
235
- </template>
236
- ```
237
-
238
245
  ## Props
239
246
 
240
- | 参数 | 说明 | 类型 | 默认值 |
241
- |------|------|------|--------|
242
- | modelValue | Markdown 内容(v-model) | `string` | - |
243
- | plugins | 自定义插件数组 | `Array<any>` | `[]` |
244
- | options | MarkdownIt 配置选项 | `MarkdownItOptions` | 见下方默认配置 |
245
- | onCopy | 复制代码回调 | `(code: string) => void` | - |
246
- | copyText | 复制按钮文本 | `string` | `'复制代码'` |
247
- | expandText | 展开按钮文本 | `string` | `'展开'` |
248
- | collapseText | 收起按钮文本 | `string` | `'收起'` |
249
- | codeMaxHeight | 代码块最大高度(行数),超过则折叠 | `number` | `20` |
247
+ | 参数 | 说明 | 类型 | 默认值 |
248
+ | ------------- | ------------------------------------------------- | -------------------------- | -------------- |
249
+ | modelValue | Markdown 内容(v-model) | `string` | - |
250
+ | plugins | 自定义插件数组 | `Array<any>` | `[]` |
251
+ | options | MarkdownIt 配置选项 | `MarkdownItOptions` | 见下方默认配置 |
252
+ | onCopy | 复制代码回调 | `(code: string) => void` | - |
253
+ | copyText | 复制按钮文本 | `string` | `'复制代码'` |
254
+ | expandText | 展开按钮文本 | `string` | `'展开'` |
255
+ | collapseText | 收起按钮文本 | `string` | `'收起'` |
256
+ | codeMaxHeight | 代码块最大高度(行数),超过则折叠 | `number` | `20` |
257
+ | afterRender | MarkdownIt 实例创建后的回调,可用于添加自定义规则 | `(md: MarkdownIt) => void` | - |
250
258
 
251
259
  ### MarkdownItOptions 默认配置
252
260
 
253
- | 参数 | 默认值 | 说明 |
254
- |------|--------|------|
255
- | html | `true` | 允许 HTML 标签 |
256
- | linkify | `true` | 自动识别链接 |
257
- | breaks | `false` | 启用换行符转换 |
258
- | typographer | `true` | 启用排版优化 |
259
- | table | `true` | 启用表格支持 |
260
- | xhtmlOut | `false` | 关闭 XHTML 严格模式 |
261
+ | 参数 | 默认值 | 说明 |
262
+ | ----------- | ------- | ------------------- |
263
+ | html | `true` | 允许 HTML 标签 |
264
+ | linkify | `true` | 自动识别链接 |
265
+ | breaks | `false` | 启用换行符转换 |
266
+ | typographer | `true` | 启用排版优化 |
267
+ | table | `true` | 启用表格支持 |
268
+ | xhtmlOut | `false` | 关闭 XHTML 严格模式 |
261
269
 
262
270
  ## Emits
263
271
 
264
- | 事件名 | 说明 | 参数 |
265
- |--------|------|------|
272
+ | 事件名 | 说明 | 参数 |
273
+ | ----------------- | -------------- | ----------------- |
266
274
  | update:modelValue | 内容变化时触发 | `(value: string)` |
267
275
 
268
276
  ## Expose
269
277
 
270
- | 方法名/属性 | 说明 | 类型 |
271
- |-------------|------|------|
272
- | renderInstance | MarkdownIt 实例 | `ShallowRef<MarkdownIt \| undefined>` |
273
- | execMethods | 执行 MarkdownIt 实例方法 | `(fn: (renderInstance: MarkdownIt) => void) => void` |
274
-
275
- ## 组件对比
276
-
277
- | 特性 | MdRender | MdRenderSimple |
278
- |------|----------|----------------|
279
- | 完整样式 | ✅ | ❌ |
280
- | 暗黑模式 | ✅ | ❌ |
281
- | 表格美化 | ✅ | ✅ |
282
- | 代码高亮 | ✅ | ✅ |
283
- | 代码块折叠 | ✅ | ✅ |
284
- | 代码块复制 | ✅ | ✅ |
285
- | 行号显示 | ✅ | ✅ |
286
- | 滚动同步 | ✅ | ✅ |
287
- | 体积 | 较大 | 较小 |
278
+ | 方法名/属性 | 说明 | 类型 |
279
+ | -------------- | ------------------------ | ---------------------------------------------------- |
280
+ | renderInstance | MarkdownIt 实例 | `ShallowRef<MarkdownIt \| undefined>` |
281
+ | execMethods | 执行 MarkdownIt 实例方法 | `(fn: (renderInstance: MarkdownIt) => void) => void` |
288
282
 
289
283
  ## 样式说明
290
284
 
291
285
  ### 内置样式
292
286
 
293
287
  `MdRender` 组件内置了完整的 Markdown 渲染样式,包括:
288
+
294
289
  - 标题样式(h1-h6)
295
290
  - 段落样式
296
291
  - 列表样式
package/dist/index.d.ts CHANGED
@@ -7,7 +7,6 @@ import { PublicProps } from 'vue';
7
7
  import { ShallowRef } from 'vue';
8
8
 
9
9
  declare type __VLS_Props = {
10
- modelValue: string;
11
10
  plugins?: Array<any>;
12
11
  options?: MarkdownItOptions;
13
12
  onCopy?: (code: string) => void;
@@ -15,23 +14,14 @@ declare type __VLS_Props = {
15
14
  expandText?: string;
16
15
  collapseText?: string;
17
16
  codeMaxHeight?: number;
18
- };
19
-
20
- declare type __VLS_Props_2 = {
21
- modelValue: string;
22
- plugins?: Array<any>;
23
- options?: MarkdownItOptions;
24
- messager?: any;
17
+ afterRender?: (md: default_2) => void;
18
+ themeMode?: 'light' | 'dark';
25
19
  };
26
20
 
27
21
  declare type __VLS_PublicProps = {
28
22
  modelValue?: string;
29
23
  } & __VLS_Props;
30
24
 
31
- declare type __VLS_PublicProps_2 = {
32
- modelValue?: string;
33
- } & __VLS_Props_2;
34
-
35
25
  export { MarkdownItOptions }
36
26
 
37
27
  export declare const MdRender: DefineComponent<__VLS_PublicProps, {
@@ -48,21 +38,7 @@ copyText: string;
48
38
  expandText: string;
49
39
  collapseText: string;
50
40
  codeMaxHeight: number;
51
- }, {}, {}, {}, string, ComponentProvideOptions, false, {
52
- containerRef: HTMLDivElement;
53
- }, HTMLElement>;
54
-
55
- export declare const MdRenderSimple: DefineComponent<__VLS_PublicProps_2, {
56
- renderInstance: ShallowRef<default_2 | undefined, default_2 | undefined>;
57
- execMethods: (fn: (renderInstance: default_2) => void) => void;
58
- }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
59
- "update:modelValue": (value: string) => any;
60
- }, string, PublicProps, Readonly<__VLS_PublicProps_2> & Readonly<{
61
- "onUpdate:modelValue"?: ((value: string) => any) | undefined;
62
- }>, {
63
- plugins: Array<any>;
64
- options: MarkdownItOptions;
65
- messager: any;
41
+ themeMode: "light" | "dark";
66
42
  }, {}, {}, {}, string, ComponentProvideOptions, false, {
67
43
  containerRef: HTMLDivElement;
68
44
  }, HTMLElement>;