@varlet/vite-plugins 2.10.0-alpha.1682067841655 → 2.10.0-alpha.1682265464192

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/markdown.js CHANGED
@@ -2,7 +2,14 @@ import markdownIt from 'markdown-it';
2
2
  import hljs from 'highlight.js';
3
3
  import { kebabCase } from '@varlet/shared';
4
4
  function htmlWrapper(html) {
5
- const hGroup = html.replace(/<h3/g, ':::<h3').replace(/<h2/g, ':::<h2').split(':::');
5
+ const matches = html.matchAll(/<h3>(.*?)<\/h3>/g);
6
+ const hGroup = html
7
+ .replace(/<h3>/g, () => {
8
+ const content = matches.next().value[1];
9
+ return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`;
10
+ })
11
+ .replace(/<h2/g, ':::<h2')
12
+ .split(':::');
6
13
  const cardGroup = hGroup
7
14
  .map((fragment) => (fragment.includes('<h3') ? `<div class="card">${fragment}</div>` : fragment))
8
15
  .join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/vite-plugins",
3
- "version": "2.10.0-alpha.1682067841655",
3
+ "version": "2.10.0-alpha.1682265464192",
4
4
  "type": "module",
5
5
  "description": "vite plugins of varlet",
6
6
  "main": "lib/index.js",
@@ -25,7 +25,7 @@
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.10.0-alpha.1682067841655"
28
+ "@varlet/shared": "2.10.0-alpha.1682265464192"
29
29
  },
30
30
  "devDependencies": {
31
31
  "vite": "^4.0.4",
package/src/markdown.ts CHANGED
@@ -4,7 +4,15 @@ import { kebabCase } from '@varlet/shared'
4
4
  import type { Plugin } from 'vite'
5
5
 
6
6
  function htmlWrapper(html: string) {
7
- const hGroup = html.replace(/<h3/g, ':::<h3').replace(/<h2/g, ':::<h2').split(':::')
7
+ const matches = html.matchAll(/<h3>(.*?)<\/h3>/g)
8
+ const hGroup = html
9
+ .replace(/<h3>/g, () => {
10
+ const content = matches.next().value[1]
11
+
12
+ return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`
13
+ })
14
+ .replace(/<h2/g, ':::<h2')
15
+ .split(':::')
8
16
 
9
17
  const cardGroup = hGroup
10
18
  .map((fragment) => (fragment.includes('<h3') ? `<div class="card">${fragment}</div>` : fragment))