@oiij/markdown-it 0.0.11 → 0.0.13

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
@@ -1,12 +1,90 @@
1
- # Use Markdown-it
1
+ # Use Markdown-it 🚀
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@oiij/markdown-it)](https://www.npmjs.com/package/@oiij/markdown-it)
4
- [![MIT-license](https://img.shields.io/npm/l/@oiij/markdown-it)](https://github.com/Eiog/@oiij/markdown-it/blob/main/LICENSE)
4
+ [![MIT-license](https://img.shields.io/npm/l/@oiij/markdown-it)](https://github.com/oiij/use/blob/main/packages/markdown-it/LICENSE)
5
5
 
6
- ## Usage
6
+ ## 项目简介 📦
7
+
8
+ Use Markdown-it 是基于 markdown-it 的 Vue 3 封装,提供便捷的 Markdown 渲染功能,帮助开发者在应用中快速渲染 Markdown 内容。
9
+
10
+ ## 功能特点 ✨
11
+
12
+ ### Markdown 渲染 📝
13
+
14
+ - ✨ 支持 CommonMark 和 GitHub Flavored Markdown
15
+ - 🎨 提供丰富的插件生态
16
+ - ⚡ 高性能渲染引擎
17
+
18
+ ### 模块化设计 🧩
19
+
20
+ - 📁 采用模块化架构,组件独立封装
21
+ - 📦 支持按需导入,减小打包体积
22
+ - 🔧 清晰的文件结构,易于维护和扩展
23
+
24
+ ### 类型安全 🔒
25
+
26
+ - 📝 完整的 TypeScript 类型定义
27
+ - 💡 提供准确的类型推断和代码提示
28
+ - 🎯 支持 Vue 3 的 Composition API 类型系统
29
+
30
+ ### 轻量高效 ⚡
31
+
32
+ - 🚀 核心代码精简,无额外依赖
33
+ - 🏃 优化的性能表现,最小化运行时开销
34
+ - 📦 支持 Tree Shaking,进一步减小打包体积
35
+
36
+ ## 安装 📥
37
+
38
+ ### 使用 pnpm 🐱
7
39
 
8
40
  ```bash
9
41
  pnpm add @oiij/markdown-it
10
42
  ```
11
43
 
12
- [在线文档](https://oiij-use.vercel.app/examples/markdown-it/started)
44
+ ### 使用 npm 📦
45
+
46
+ ```bash
47
+ npm install @oiij/markdown-it
48
+ ```
49
+
50
+ ### 使用 yarn 🧶
51
+
52
+ ```bash
53
+ yarn add @oiij/markdown-it
54
+ ```
55
+
56
+ ## 快速开始 🌟
57
+
58
+ ### 基础使用
59
+
60
+ ```vue
61
+ <script setup>
62
+ import { UseMarkdownIt } from '@oiij/markdown-it'
63
+ </script>
64
+
65
+ <template>
66
+ <UseMarkdownIt content="# Hello World" />
67
+ </template>
68
+ ```
69
+
70
+ ## 在线文档 📚
71
+
72
+ [在线文档](https://oiij-use.vercel.app/markdown-it/markdown-it) 📖
73
+
74
+ ## 贡献指南 🤝
75
+
76
+ 欢迎贡献代码、报告问题或提出新功能建议!
77
+
78
+ 1. Fork 本仓库 🍴
79
+ 2. 创建您的特性分支 (`git checkout -b feature/amazing-feature`) 🌿
80
+ 3. 提交您的更改 (`git commit -m 'Add some amazing feature'`) 💾
81
+ 4. 推送到分支 (`git push origin feature/amazing-feature`) 🚀
82
+ 5. 打开一个 Pull Request 📥
83
+
84
+ ## 许可证 📄
85
+
86
+ 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情 📑
87
+
88
+ ## 联系方式 📞
89
+
90
+ - GitHub: [https://github.com/Eiog/@oiij/markdown-it](https://github.com/Eiog/@oiij/markdown-it) 🌟
package/dist/index.d.mts CHANGED
@@ -3,19 +3,63 @@ import * as vue0 from "vue";
3
3
  import { MaybeRefOrGetter, TemplateRef } from "vue";
4
4
 
5
5
  //#region src/index.d.ts
6
+ /**
7
+ * 使用 MarkdownIt 选项类型
8
+ */
6
9
  type UseMarkDownItOptions = {
10
+ /**
11
+ * Markdown 内容
12
+ */
7
13
  value?: MaybeRefOrGetter<string>;
14
+ /**
15
+ * 是否手动渲染
16
+ * @default false
17
+ */
8
18
  manual?: boolean;
19
+ /**
20
+ * 是否使用 DOM 净化
21
+ * @default true
22
+ */
9
23
  domPurify?: boolean;
24
+ /**
25
+ * MarkdownIt 选项
26
+ */
10
27
  markdownItOptions?: Options;
11
28
  };
29
+ /**
30
+ * 使用 MarkdownIt
31
+ *
32
+ * @param templateRef - 渲染容器的模板引用
33
+ * @param options - MarkdownIt 选项
34
+ * @returns MarkdownIt 实例和工具方法
35
+ *
36
+ * @example
37
+ * ```vue
38
+ * <script setup>
39
+ * import { ref } from 'vue'
40
+ * import { useMarkdownIt } from '@oiij/markdown-it'
41
+ *
42
+ * const content = ref('# 标题\n\n这是一段 **Markdown** 内容')
43
+ * const { html, render } = useMarkdownIt({
44
+ * value: content
45
+ * })
46
+ * </script>
47
+ *
48
+ * <template>
49
+ * <div v-html="html"></div>
50
+ * </template>
51
+ * ```
52
+ */
12
53
  declare function useMarkdownIt(templateRef?: TemplateRef<HTMLElement>, options?: UseMarkDownItOptions): {
13
54
  templateRef: Readonly<vue0.ShallowRef<HTMLElement | null>> | undefined;
14
- valueRef: vue0.Ref<string | undefined, string | undefined>;
15
- htmlRef: vue0.Ref<string, string>;
55
+ value: vue0.Ref<string | undefined, string | undefined>;
56
+ html: vue0.Ref<string, string>;
16
57
  markdownItInst: markdownIt;
17
58
  render: (value?: string) => string;
18
59
  };
60
+ /**
61
+ * MarkdownIt 返回值类型
62
+ */
19
63
  type MarkdownItReturns = ReturnType<typeof useMarkdownIt>;
20
64
  //#endregion
21
65
  export { MarkdownItReturns, UseMarkDownItOptions, useMarkdownIt };
package/dist/index.mjs CHANGED
@@ -17,6 +17,30 @@ function watchRefOrGetter(value, callback) {
17
17
 
18
18
  //#endregion
19
19
  //#region src/index.ts
20
+ /**
21
+ * 使用 MarkdownIt
22
+ *
23
+ * @param templateRef - 渲染容器的模板引用
24
+ * @param options - MarkdownIt 选项
25
+ * @returns MarkdownIt 实例和工具方法
26
+ *
27
+ * @example
28
+ * ```vue
29
+ * <script setup>
30
+ * import { ref } from 'vue'
31
+ * import { useMarkdownIt } from '@oiij/markdown-it'
32
+ *
33
+ * const content = ref('# 标题\n\n这是一段 **Markdown** 内容')
34
+ * const { html, render } = useMarkdownIt({
35
+ * value: content
36
+ * })
37
+ * <\/script>
38
+ *
39
+ * <template>
40
+ * <div v-html="html"></div>
41
+ * </template>
42
+ * ```
43
+ */
20
44
  function useMarkdownIt(templateRef, options) {
21
45
  const { value, manual = false, domPurify = true, markdownItOptions } = options ?? {};
22
46
  const valueRef = watchRefOrGetter(value, () => {
@@ -24,8 +48,23 @@ function useMarkdownIt(templateRef, options) {
24
48
  });
25
49
  const htmlRef = ref("");
26
50
  const markdownItInst = markdownIt({ ...markdownItOptions });
51
+ /**
52
+ * 渲染 Markdown 内容
53
+ *
54
+ * @param value - Markdown 内容
55
+ * @returns 渲染后的 HTML 内容
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { useMarkdownIt } from '@oiij/markdown-it'
60
+ *
61
+ * const { render } = useMarkdownIt()
62
+ * const html = render('# 标题')
63
+ * console.log(html) // <h1>标题</h1>
64
+ * ```
65
+ */
27
66
  function render(value) {
28
- if (value) valueRef.value = value;
67
+ if (value !== void 0 && value !== valueRef.value) valueRef.value = value;
29
68
  const mdValue = markdownItInst.render(valueRef.value ?? "");
30
69
  htmlRef.value = domPurify ? DOMPurify.sanitize(mdValue) : mdValue;
31
70
  if (templateRef?.value) templateRef.value.innerHTML = htmlRef.value;
@@ -39,8 +78,8 @@ function useMarkdownIt(templateRef, options) {
39
78
  });
40
79
  return {
41
80
  templateRef,
42
- valueRef,
43
- htmlRef,
81
+ value: valueRef,
82
+ html: htmlRef,
44
83
  markdownItInst,
45
84
  render
46
85
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oiij/markdown-it",
3
3
  "type": "module",
4
- "version": "0.0.11",
4
+ "version": "0.0.13",
5
5
  "description": "A Vue Composable for markdown-it",
6
6
  "author": "oiij",
7
7
  "license": "MIT",