/g, '')
21 | }
22 |
23 | function highlight(str, lang) {
24 | if (lang && hljs.getLanguage(lang)) {
25 | return `${
26 | hljs.highlight(str, { language: lang, ignoreIllegals: true }).value
27 | }
`
28 | }
29 | return ''
30 | }
31 |
32 | function markdownToVue(source, id, options) {
33 | const { data, content: contentSource } = matter(source)
34 | const md = markdown({
35 | html: true,
36 | typographer: true,
37 | highlight,
38 | })
39 | const customBlock = ['info', 'error', 'warning', 'tips']
40 | const defaultCustomBlockTitle = {
41 | info: '消息',
42 | error: '错误',
43 | warning: '警告',
44 | tips: '提示',
45 | }
46 | customBlock.forEach((item) => {
47 | md.use(markdownContainer, item, {
48 | render(tokens, idx) {
49 | const reg = new RegExp(`^${item}\\s+(.*)$`)
50 | const m = tokens[idx].info.trim().match(reg) || [
51 | null,
52 | defaultCustomBlockTitle[item],
53 | ]
54 |
55 | if (tokens[idx].nesting === 1) {
56 | return (
57 | `` +
58 | `${md.utils.escapeHtml(
59 | m[1]
60 | )}\n`
61 | )
62 | }
63 | return '\n'
64 | },
65 | })
66 | })
67 |
68 | const res = md.render(contentSource)
69 |
70 | const templateString = splitCard(res)
71 |
72 | return `
73 | ${templateString}
74 |
75 |
81 | `
82 | }
83 |
84 | function MarkdownVitePlugin(options) {
85 | return {
86 | name: 'lin-markdown-to-vue-vite-plugin',
87 | enforce: 'pre',
88 | transform(source, id) {
89 | if (!/\.md$/.test(id)) {
90 | return undefined
91 | }
92 | try {
93 | return markdownToVue(source, id, options)
94 | } catch (e) {
95 | this.error(e)
96 | return undefined
97 | }
98 | },
99 | async handleHotUpdate(ctx) {
100 | if (!/\.md$/.test(ctx.file)) return
101 |
102 | const readSource = ctx.read
103 | ctx.read = async function () {
104 | return markdownToVue(await readSource(), options)
105 | }
106 | },
107 | }
108 | }
109 |
110 | module.exports = MarkdownVitePlugin
111 |
--------------------------------------------------------------------------------
/packages/markdown-to-vue/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@lin-ui-vue/markdown-to-vue",
3 | "version": "0.0.1",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "fs-extra": "^10.1.0",
14 | "gray-matter": "^4.0.3",
15 | "highlight.js": "^11.5.1",
16 | "markdown-it": "^13.0.1",
17 | "markdown-it-container": "^3.0.0"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/packages/ui/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/packages/ui/.lin-ui-vue/components.json:
--------------------------------------------------------------------------------
1 | [
2 | "avatar",
3 | "button",
4 | "icon",
5 | "tag",
6 | "config-provider",
7 | "card",
8 | "image",
9 | "lazy",
10 | "row",
11 | "col",
12 | "Cell"
13 | ]
14 |
--------------------------------------------------------------------------------
/packages/ui/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["Vue.volar"]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/ui/README.md:
--------------------------------------------------------------------------------
1 | # Vue 3 + TypeScript + Vite
2 |
3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `
12 |