@deot/docs-markdown 1.0.1
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 +145 -0
- package/dist/index.cjs +827 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +798 -0
- package/dist/index.style.css +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @deot/docs-markdown
|
|
2
|
+
|
|
3
|
+
`@deot/docs-markdown` 提供 Vue 3 Markdown 渲染组件,内置文档指示器、标题锚点、链接识别、tip/warning 容器、代码高亮预览和按需加载的 Playground 容器。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @deot/docs-markdown @deot/docs-locale @deot/vc vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<template>
|
|
15
|
+
<Markdown :value="source" :locale="zhCN" />
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { ref } from 'vue';
|
|
20
|
+
import { Markdown } from '@deot/docs-markdown';
|
|
21
|
+
import { zhCN } from '@deot/docs-locale';
|
|
22
|
+
import '@deot/docs-markdown/dist/index.style.css';
|
|
23
|
+
|
|
24
|
+
const source = ref('# Hello @deot/docs');
|
|
25
|
+
</script>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
组件接受 `modelValue` 或 `value` 字符串。当前组件负责渲染,不会修改传入的 Markdown 内容。
|
|
29
|
+
`locale` 可显式传入 `Language`;未传入时优先使用上层 `provideLocale()`,否则回退到 `en-US`。
|
|
30
|
+
|
|
31
|
+
## 文档指示器
|
|
32
|
+
|
|
33
|
+
指示器默认开启。它会把标题、段落、列表、代码块等文档块压缩成纵向刻度,支持悬停预览、点击定位和拖动浏览:
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<Markdown
|
|
37
|
+
:value="source"
|
|
38
|
+
:indicator="{
|
|
39
|
+
position: 'right',
|
|
40
|
+
preview: true,
|
|
41
|
+
draggable: true,
|
|
42
|
+
height: 'min(72vh, 600px)'
|
|
43
|
+
}"
|
|
44
|
+
/>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
传入 `:indicator="false"` 可以完全关闭;传入 `true` 或省略该属性时使用默认配置。对象支持以下参数:
|
|
48
|
+
|
|
49
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
50
|
+
| --- | --- | --- | --- |
|
|
51
|
+
| `preview` | `boolean` | `true` | 是否展示悬停摘要。 |
|
|
52
|
+
| `draggable` | `boolean` | `true` | 是否允许拖动快速浏览。 |
|
|
53
|
+
| `position` | `'left' \| 'right'` | `'right'` | 指示器所在侧。 |
|
|
54
|
+
| `top` | `number \| string` | `0` | 相对滚动容器垂直中心的偏移,默认上下居中。 |
|
|
55
|
+
| `height` | `number \| string` | `min(72vh, 600px)` | 指示器的可视高度。 |
|
|
56
|
+
|
|
57
|
+
## Markdown 扩展
|
|
58
|
+
|
|
59
|
+
### 提示容器
|
|
60
|
+
|
|
61
|
+
````markdown
|
|
62
|
+
:::tip
|
|
63
|
+
这是一段提示。
|
|
64
|
+
:::
|
|
65
|
+
|
|
66
|
+
:::warning
|
|
67
|
+
这是一段警告。
|
|
68
|
+
:::
|
|
69
|
+
````
|
|
70
|
+
|
|
71
|
+
### 单文件 Playground
|
|
72
|
+
|
|
73
|
+
````markdown
|
|
74
|
+
:::playground
|
|
75
|
+
```vue
|
|
76
|
+
<template>
|
|
77
|
+
<strong>Hello Playground</strong>
|
|
78
|
+
</template>
|
|
79
|
+
```
|
|
80
|
+
:::
|
|
81
|
+
````
|
|
82
|
+
|
|
83
|
+
### 多文件 Playground
|
|
84
|
+
|
|
85
|
+
多文件模式要求每个 fence 声明唯一文件名。可以在 HTML 注释中的 JSON5 配置里指定入口、视图和视口:
|
|
86
|
+
|
|
87
|
+
````markdown
|
|
88
|
+
:::playground
|
|
89
|
+
<!--
|
|
90
|
+
<config lang="json5">
|
|
91
|
+
{
|
|
92
|
+
entry: 'main.js',
|
|
93
|
+
views: ['runtime', 'files'],
|
|
94
|
+
viewport: 375,
|
|
95
|
+
viewportOptions: ['auto', 375, [375, 667]]
|
|
96
|
+
}
|
|
97
|
+
</config>
|
|
98
|
+
-->
|
|
99
|
+
```js main.js
|
|
100
|
+
import { createApp } from 'vue';
|
|
101
|
+
import App from './App.vue';
|
|
102
|
+
|
|
103
|
+
createApp(App).mount('#app');
|
|
104
|
+
```
|
|
105
|
+
```vue App.vue
|
|
106
|
+
<template>
|
|
107
|
+
<h1>Hello</h1>
|
|
108
|
+
</template>
|
|
109
|
+
```
|
|
110
|
+
:::
|
|
111
|
+
````
|
|
112
|
+
|
|
113
|
+
支持的 `views` 值为 `runtime` 和 `files`。`viewport` 可为 `auto`、正数宽度或 `[width, height]`。
|
|
114
|
+
|
|
115
|
+
Playground 会在浏览器里编译 Vue SFC 的 `<style lang="scss">` 以及独立 `.scss` / `.sass` 文件。下划线 partial(如 `_variables.scss`)只作为 `@use` 依赖,不会单独注入预览。
|
|
116
|
+
|
|
117
|
+
Playground 只在页面出现 fence 或 `:::playground` 时动态加载。使用 Playground 容器时,还需要加载 `@deot/docs-playground/dist/index.style.css` 和宿主应用使用的 `@deot/vc-components` 样式。
|
|
118
|
+
|
|
119
|
+
## 公共 API
|
|
120
|
+
|
|
121
|
+
| 导出 | 说明 |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `Markdown` | Vue Markdown 渲染组件。 |
|
|
124
|
+
| `parseMarkdownSearchSections(content)` | 使用渲染器相同的标题锚点规则提取文档标题、正文和小节,供搜索索引使用。 |
|
|
125
|
+
|
|
126
|
+
类型:`MarkdownSearchDocument`、`MarkdownSearchSection`、`MarkdownIndicatorConfig`、`MarkdownIndicatorOptions`、`MarkdownPlaygroundConfig`、`MarkdownPlaygroundMountProps`。
|
|
127
|
+
|
|
128
|
+
底层 markdown-it 实例和内部指令不是包入口的公共导出。搜索解析结果不会包含代码围栏和 HTML 内容。
|
|
129
|
+
|
|
130
|
+
## 仓库内 examples
|
|
131
|
+
|
|
132
|
+
在 monorepo 根目录执行 `npm run dev` 可预览 [`packages/markdown/examples`](examples/) 下的 Markdown 与 Playground 容器示例。
|
|
133
|
+
|
|
134
|
+
## 仓库内验证
|
|
135
|
+
|
|
136
|
+
在仓库根目录执行:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm run test -- --package-name markdown
|
|
140
|
+
npm run build -- --package-name markdown
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 许可证
|
|
144
|
+
|
|
145
|
+
MIT
|