@kernelift/markdown 1.1.2 → 1.1.3
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 +82 -58
- package/dist/index.d.ts +10 -3
- package/dist/index.js +818 -785
- package/dist/markdown.css +1 -1
- package/package.json +1 -1
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,
|
|
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
|
-
|
|
158
|
-
|
|
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,10 +237,7 @@ 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
|
```
|
|
@@ -237,60 +259,62 @@ const content = ref('# Hello World');
|
|
|
237
259
|
|
|
238
260
|
## Props
|
|
239
261
|
|
|
240
|
-
| 参数
|
|
241
|
-
|
|
242
|
-
| modelValue
|
|
243
|
-
| plugins
|
|
244
|
-
| options
|
|
245
|
-
| onCopy
|
|
246
|
-
| copyText
|
|
247
|
-
| expandText
|
|
248
|
-
| collapseText
|
|
249
|
-
| codeMaxHeight | 代码块最大高度(行数),超过则折叠
|
|
262
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
263
|
+
| ------------- | ------------------------------------------------- | -------------------------- | -------------- |
|
|
264
|
+
| modelValue | Markdown 内容(v-model) | `string` | - |
|
|
265
|
+
| plugins | 自定义插件数组 | `Array<any>` | `[]` |
|
|
266
|
+
| options | MarkdownIt 配置选项 | `MarkdownItOptions` | 见下方默认配置 |
|
|
267
|
+
| onCopy | 复制代码回调 | `(code: string) => void` | - |
|
|
268
|
+
| copyText | 复制按钮文本 | `string` | `'复制代码'` |
|
|
269
|
+
| expandText | 展开按钮文本 | `string` | `'展开'` |
|
|
270
|
+
| collapseText | 收起按钮文本 | `string` | `'收起'` |
|
|
271
|
+
| codeMaxHeight | 代码块最大高度(行数),超过则折叠 | `number` | `20` |
|
|
272
|
+
| afterRender | MarkdownIt 实例创建后的回调,可用于添加自定义规则 | `(md: MarkdownIt) => void` | - |
|
|
250
273
|
|
|
251
274
|
### MarkdownItOptions 默认配置
|
|
252
275
|
|
|
253
|
-
| 参数
|
|
254
|
-
|
|
255
|
-
| html
|
|
256
|
-
| linkify
|
|
257
|
-
| breaks
|
|
258
|
-
| typographer | `true`
|
|
259
|
-
| table
|
|
260
|
-
| xhtmlOut
|
|
276
|
+
| 参数 | 默认值 | 说明 |
|
|
277
|
+
| ----------- | ------- | ------------------- |
|
|
278
|
+
| html | `true` | 允许 HTML 标签 |
|
|
279
|
+
| linkify | `true` | 自动识别链接 |
|
|
280
|
+
| breaks | `false` | 启用换行符转换 |
|
|
281
|
+
| typographer | `true` | 启用排版优化 |
|
|
282
|
+
| table | `true` | 启用表格支持 |
|
|
283
|
+
| xhtmlOut | `false` | 关闭 XHTML 严格模式 |
|
|
261
284
|
|
|
262
285
|
## Emits
|
|
263
286
|
|
|
264
|
-
| 事件名
|
|
265
|
-
|
|
287
|
+
| 事件名 | 说明 | 参数 |
|
|
288
|
+
| ----------------- | -------------- | ----------------- |
|
|
266
289
|
| update:modelValue | 内容变化时触发 | `(value: string)` |
|
|
267
290
|
|
|
268
291
|
## Expose
|
|
269
292
|
|
|
270
|
-
| 方法名/属性
|
|
271
|
-
|
|
272
|
-
| renderInstance | MarkdownIt 实例
|
|
273
|
-
| execMethods
|
|
293
|
+
| 方法名/属性 | 说明 | 类型 |
|
|
294
|
+
| -------------- | ------------------------ | ---------------------------------------------------- |
|
|
295
|
+
| renderInstance | MarkdownIt 实例 | `ShallowRef<MarkdownIt \| undefined>` |
|
|
296
|
+
| execMethods | 执行 MarkdownIt 实例方法 | `(fn: (renderInstance: MarkdownIt) => void) => void` |
|
|
274
297
|
|
|
275
298
|
## 组件对比
|
|
276
299
|
|
|
277
|
-
| 特性
|
|
278
|
-
|
|
279
|
-
| 完整样式
|
|
280
|
-
| 暗黑模式
|
|
281
|
-
| 表格美化
|
|
282
|
-
| 代码高亮
|
|
283
|
-
| 代码块折叠 | ✅
|
|
284
|
-
| 代码块复制 | ✅
|
|
285
|
-
| 行号显示
|
|
286
|
-
| 滚动同步
|
|
287
|
-
| 体积
|
|
300
|
+
| 特性 | MdRender | MdRenderSimple |
|
|
301
|
+
| ---------- | -------- | -------------- |
|
|
302
|
+
| 完整样式 | ✅ | ❌ |
|
|
303
|
+
| 暗黑模式 | ✅ | ❌ |
|
|
304
|
+
| 表格美化 | ✅ | ✅ |
|
|
305
|
+
| 代码高亮 | ✅ | ✅ |
|
|
306
|
+
| 代码块折叠 | ✅ | ✅ |
|
|
307
|
+
| 代码块复制 | ✅ | ✅ |
|
|
308
|
+
| 行号显示 | ✅ | ✅ |
|
|
309
|
+
| 滚动同步 | ✅ | ✅ |
|
|
310
|
+
| 体积 | 较大 | 较小 |
|
|
288
311
|
|
|
289
312
|
## 样式说明
|
|
290
313
|
|
|
291
314
|
### 内置样式
|
|
292
315
|
|
|
293
316
|
`MdRender` 组件内置了完整的 Markdown 渲染样式,包括:
|
|
317
|
+
|
|
294
318
|
- 标题样式(h1-h6)
|
|
295
319
|
- 段落样式
|
|
296
320
|
- 列表样式
|
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,13 +14,18 @@ declare type __VLS_Props = {
|
|
|
15
14
|
expandText?: string;
|
|
16
15
|
collapseText?: string;
|
|
17
16
|
codeMaxHeight?: number;
|
|
17
|
+
afterRender?: (md: default_2) => void;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
declare type __VLS_Props_2 = {
|
|
21
21
|
modelValue: string;
|
|
22
22
|
plugins?: Array<any>;
|
|
23
23
|
options?: MarkdownItOptions;
|
|
24
|
-
|
|
24
|
+
onCopy?: (code: string) => void;
|
|
25
|
+
copyText?: string;
|
|
26
|
+
expandText?: string;
|
|
27
|
+
collapseText?: string;
|
|
28
|
+
codeMaxHeight?: number;
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
declare type __VLS_PublicProps = {
|
|
@@ -62,7 +66,10 @@ execMethods: (fn: (renderInstance: default_2) => void) => void;
|
|
|
62
66
|
}>, {
|
|
63
67
|
plugins: Array<any>;
|
|
64
68
|
options: MarkdownItOptions;
|
|
65
|
-
|
|
69
|
+
copyText: string;
|
|
70
|
+
expandText: string;
|
|
71
|
+
collapseText: string;
|
|
72
|
+
codeMaxHeight: number;
|
|
66
73
|
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
67
74
|
containerRef: HTMLDivElement;
|
|
68
75
|
}, HTMLElement>;
|