@varlet/vite-plugins 2.18.0-alpha.1697559303154 → 2.18.0

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/lib/index.js CHANGED
@@ -2,11 +2,15 @@
2
2
  import markdownIt from "markdown-it";
3
3
  import hljs from "highlight.js";
4
4
  import { kebabCase } from "@varlet/shared";
5
+ import { pinyin } from "pinyin";
6
+ function transformHash(hash) {
7
+ return pinyin(hash, { style: "tone2" }).flat(Infinity).join("-").replaceAll(" ", "-");
8
+ }
5
9
  function htmlWrapper(html2) {
6
10
  const matches = html2.matchAll(/<h3>(.*?)<\/h3>/g);
7
11
  const hGroup = html2.replace(/<h3>/g, () => {
8
- const content = matches.next().value[1];
9
- return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`;
12
+ const hash = transformHash(matches.next().value[1]);
13
+ return `:::<h3 id="${hash}"><router-link to="#${hash}">#</router-link>`;
10
14
  }).replace(/<h2/g, ":::<h2").split(":::");
11
15
  const cardGroup = hGroup.map((fragment) => fragment.includes("<h3") ? `<div class="card">${fragment}</div>` : fragment).join("");
12
16
  return cardGroup.replace(/<code>/g, "<code v-pre>");
@@ -94,16 +98,7 @@ function markdown(options) {
94
98
  return markdownToVue(source, options);
95
99
  } catch (e) {
96
100
  this.error(e);
97
- return "";
98
101
  }
99
- },
100
- async handleHotUpdate(ctx) {
101
- if (!/\.md$/.test(ctx.file))
102
- return;
103
- const readSource = ctx.read;
104
- ctx.read = async function() {
105
- return markdownToVue(await readSource(), options);
106
- };
107
102
  }
108
103
  };
109
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/vite-plugins",
3
- "version": "2.18.0-alpha.1697559303154",
3
+ "version": "2.18.0",
4
4
  "type": "module",
5
5
  "description": "vite plugins of varlet",
6
6
  "main": "lib/index.js",
@@ -25,16 +25,17 @@
25
25
  "fs-extra": "^9.0.1",
26
26
  "highlight.js": "^10.7.2",
27
27
  "markdown-it": "^12.2.3",
28
- "@varlet/shared": "2.18.0-alpha.1697559303154"
28
+ "pinyin": "3.0.0-alpha.4",
29
+ "@varlet/shared": "2.18.0"
29
30
  },
30
31
  "devDependencies": {
31
- "tsup": "7.2.0",
32
- "vite": "4.3.5",
33
- "typescript": "^5.1.5",
34
- "@types/node": "^18.7.20",
35
32
  "@types/ejs": "^3.1.1",
33
+ "@types/fs-extra": "^9.0.2",
36
34
  "@types/markdown-it": "^12.2.3",
37
- "@types/fs-extra": "^9.0.2"
35
+ "@types/node": "^18.7.20",
36
+ "tsup": "7.2.0",
37
+ "typescript": "^5.1.5",
38
+ "vite": "4.3.5"
38
39
  },
39
40
  "scripts": {
40
41
  "dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
package/src/markdown.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  import markdownIt from 'markdown-it'
2
2
  import hljs from 'highlight.js'
3
3
  import { kebabCase } from '@varlet/shared'
4
+ import { pinyin } from 'pinyin'
4
5
  import type { Plugin } from 'vite'
5
6
 
7
+ function transformHash(hash: string) {
8
+ return pinyin(hash, { style: 'tone2' }).flat(Infinity).join('-').replaceAll(' ', '-')
9
+ }
10
+
6
11
  function htmlWrapper(html: string) {
7
12
  const matches = html.matchAll(/<h3>(.*?)<\/h3>/g)
8
13
  const hGroup = html
9
14
  .replace(/<h3>/g, () => {
10
- const content = matches.next().value[1]
15
+ const hash = transformHash(matches.next().value[1])
11
16
 
12
- return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`
17
+ return `:::<h3 id="${hash}"><router-link to="#${hash}">#</router-link>`
13
18
  })
14
19
  .replace(/<h2/g, ':::<h2')
15
20
  .split(':::')
@@ -133,16 +138,6 @@ export function markdown(options: MarkdownOptions): Plugin {
133
138
  return markdownToVue(source, options)
134
139
  } catch (e: any) {
135
140
  this.error(e)
136
- return ''
137
- }
138
- },
139
-
140
- async handleHotUpdate(ctx) {
141
- if (!/\.md$/.test(ctx.file)) return
142
-
143
- const readSource = ctx.read
144
- ctx.read = async function () {
145
- return markdownToVue(await readSource(), options)
146
141
  }
147
142
  },
148
143
  }