Skip to content

Commit b0fc856

Browse files
committed
refactor(markdown): bump sfc plugin to v0.9
BREAKING CHANGE: type of node-api `page.sfcBlocks` has been changed
1 parent 1c861b6 commit b0fc856

File tree

7 files changed

+68
-59
lines changed

7 files changed

+68
-59
lines changed

docs/reference/node-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ Therefore, it's not recommended to store large amounts of info into route meta,
640640

641641
### sfcBlocks
642642

643-
- Type: `string[]`
643+
- Type: `MarkdownSfcBlocks`
644644

645645
- Details:
646646

docs/zh/reference/node-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ interface MarkdownLink {
639639

640640
### sfcBlocks
641641

642-
- 类型: `string[]`
642+
- 类型: `MarkdownSfcBlocks`
643643

644644
- 详情:
645645

packages/@vuepress/core/src/app/prepare/preparePageComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ export const preparePageComponent = async (
1010
await app.writeTemp(
1111
page.componentFilePathRelative,
1212
[
13-
// take the rendered markdown content as <template>
14-
// #688: wrap the content with a <div> to avoid some potential issues of fragment component
15-
`<template><div>${page.contentRendered}</div></template>\n`,
13+
// #688: wrap the content of `<template>` with a `<div>` to avoid some potential issues of fragment component
14+
`${page.sfcBlocks.template?.tagOpen}<div>${page.sfcBlocks.template?.contentStripped}</div>${page.sfcBlocks.template?.tagClose}\n`,
1615
// hoist `<script>`, `<style>` and other custom blocks
17-
...page.sfcBlocks,
16+
page.sfcBlocks.script?.content,
17+
page.sfcBlocks.scriptSetup?.content,
18+
...page.sfcBlocks.styles.map((item) => item.content),
19+
...page.sfcBlocks.customBlocks.map((item) => item.content),
1820
].join('\n')
1921
)
2022
}

packages/@vuepress/core/src/page/renderPageContent.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
MarkdownEnv,
33
MarkdownHeader,
44
MarkdownLink,
5+
MarkdownSfcBlocks,
56
} from '@vuepress/markdown'
67
import type { App, PageFrontmatter, PageOptions } from '../types'
78

@@ -27,7 +28,7 @@ export const renderPageContent = async ({
2728
frontmatter: PageFrontmatter
2829
headers: MarkdownHeader[]
2930
links: MarkdownLink[]
30-
sfcBlocks: string[]
31+
sfcBlocks: MarkdownSfcBlocks
3132
title: string
3233
}> => {
3334
const markdownEnv: MarkdownEnv = {
@@ -46,7 +47,13 @@ export const renderPageContent = async ({
4647
headers = [],
4748
importedFiles = [],
4849
links = [],
49-
sfcBlocks = [],
50+
sfcBlocks = {
51+
template: null,
52+
script: null,
53+
scriptSetup: null,
54+
styles: [],
55+
customBlocks: [],
56+
},
5057
title = '',
5158
} = markdownEnv
5259

packages/@vuepress/core/src/types/page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MarkdownLink } from '@vuepress/markdown'
1+
import type { MarkdownLink, MarkdownSfcBlocks } from '@vuepress/markdown'
22
import type { PageBase, PageData, PageFrontmatter } from '@vuepress/shared'
33

44
/**
@@ -77,7 +77,7 @@ export type Page<
7777
/**
7878
* Extracted sfc blocks of the page
7979
*/
80-
sfcBlocks: string[]
80+
sfcBlocks: MarkdownSfcBlocks
8181

8282
/**
8383
* Slug of the page

packages/@vuepress/markdown/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"clean": "rimraf lib *.tsbuildinfo"
2727
},
2828
"dependencies": {
29-
"@mdit-vue/plugin-component": "^0.7.1",
30-
"@mdit-vue/plugin-frontmatter": "^0.7.1",
31-
"@mdit-vue/plugin-headers": "^0.7.1",
32-
"@mdit-vue/plugin-sfc": "^0.7.1",
33-
"@mdit-vue/plugin-title": "^0.7.1",
34-
"@mdit-vue/plugin-toc": "^0.7.1",
35-
"@mdit-vue/shared": "^0.7.1",
36-
"@mdit-vue/types": "^0.7.1",
29+
"@mdit-vue/plugin-component": "^0.9.0",
30+
"@mdit-vue/plugin-frontmatter": "^0.9.1",
31+
"@mdit-vue/plugin-headers": "^0.9.1",
32+
"@mdit-vue/plugin-sfc": "^0.9.1",
33+
"@mdit-vue/plugin-title": "^0.9.1",
34+
"@mdit-vue/plugin-toc": "^0.9.1",
35+
"@mdit-vue/shared": "^0.9.1",
36+
"@mdit-vue/types": "^0.9.0",
3737
"@types/markdown-it": "^12.2.3",
3838
"@types/markdown-it-emoji": "^2.0.2",
3939
"@vuepress/shared": "workspace:*",

pnpm-lock.yaml

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)