diff --git a/CHANGELOG.md b/CHANGELOG.md index 06905ccc..5c5170f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,44 @@ +# [1.0.0-rc.33](https://github.com/vuejs/vitepress/compare/v1.0.0-rc.32...v1.0.0-rc.33) (2023-12-26) + +### Features + +- allow explicitly mark code element as `.vp-copy-ignore` ([#3360](https://github.com/vuejs/vitepress/issues/3360)) ([93122ee](https://github.com/vuejs/vitepress/commit/93122eee20cb6586026c1ffac04d9787861cc2f3)) +- **build:** enable VUE_PROD_HYDRATION_MISMATCH_DETAILS when DEBUG is truthy ([f4d4280](https://github.com/vuejs/vitepress/commit/f4d4280d7d1728a966bb04968a9bac10470c3d06)), closes [#422](https://github.com/vuejs/vitepress/issues/422) + +### Performance Improvements + +- implement concurrent promise pooling for render task ([#3366](https://github.com/vuejs/vitepress/issues/3366)) + +# [1.0.0-rc.32](https://github.com/vuejs/vitepress/compare/v1.0.0-rc.31...v1.0.0-rc.32) (2023-12-16) + +### Features + +- allow ignoring node in header ([#3331](https://github.com/vuejs/vitepress/issues/3331)) ([e4bf1e4](https://github.com/vuejs/vitepress/commit/e4bf1e48e6a1592d583b218425c1fa7497955dc5)) +- expose `shikijiSetup` hook ([#3344](https://github.com/vuejs/vitepress/issues/3344)) ([d12e23d](https://github.com/vuejs/vitepress/commit/d12e23ddf69480418078ff39846c99ecf2e1eb1b)) +- update shikiji, support twoslash ([#3339](https://github.com/vuejs/vitepress/issues/3339)) ([8800195](https://github.com/vuejs/vitepress/commit/880019545795fd075be89d94794bfbd05af461b5)) + +# [1.0.0-rc.31](https://github.com/vuejs/vitepress/compare/v1.0.0-rc.30...v1.0.0-rc.31) (2023-11-25) + +### Bug Fixes + +- **build:** make assets go through vite pipeline during dev too ([#3258](https://github.com/vuejs/vitepress/issues/3258)) ([c3d7f22](https://github.com/vuejs/vitepress/commit/c3d7f22bd313b09e6965ac3125ea662ce283ed2d)) +- **theme:** use VPLink for links in VPDocFooter ([#3248](https://github.com/vuejs/vitepress/issues/3248)) ([479a320](https://github.com/vuejs/vitepress/commit/479a320731313b8e7e0bad3f8383ae6bc05ed8e2)) + +# [1.0.0-rc.30](https://github.com/vuejs/vitepress/compare/v1.0.0-rc.29...v1.0.0-rc.30) (2023-11-23) + +### Bug Fixes + +- **client:** no onAfterRouteChanged called after popstate ([#3227](https://github.com/vuejs/vitepress/issues/3227)) ([60fc8fd](https://github.com/vuejs/vitepress/commit/60fc8fd24460eede1dc73768ad0aa53616da746f)), closes [#3226](https://github.com/vuejs/vitepress/issues/3226) +- **theme:** remove double padding from sidebar ([ef6d8d1](https://github.com/vuejs/vitepress/commit/ef6d8d1e4295c6ff967c17b5b9c20c04843da5a0)), closes [#3228](https://github.com/vuejs/vitepress/issues/3228) + +### Features + +- migrate to shikiji ([#3237](https://github.com/vuejs/vitepress/pull/3237)) ([75f18e4](https://github.com/vuejs/vitepress/commit/75f18e47334933b642d14b8b69b372cb1ebd4244)) + +### BREAKING CHANGES + +- VitePress now uses shikiji instead of shiki for syntax highlighting. If you're using features like adding extra languages or custom aliases, please refer [shikiji docs](https://github.com/antfu/shikiji) for migration guide or comment on [#3237](https://github.com/vuejs/vitepress/pull/3237) if you need help. + # [1.0.0-rc.29](https://github.com/vuejs/vitepress/compare/v1.0.0-rc.28...v1.0.0-rc.29) (2023-11-19) ### Bug Fixes diff --git a/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts b/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts index aa1f6ff2..42a89891 100644 --- a/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts +++ b/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts @@ -163,19 +163,19 @@ describe('Line Numbers', () => { describe('Import Code Snippets', () => { test('basic', async () => { const lines = page.locator('#basic-code-snippet + div code > span') - expect(await lines.count()).toBe(22) + expect(await lines.count()).toBe(11) }) test('specify region', async () => { const lines = page.locator('#specify-region + div code > span') - expect(await lines.count()).toBe(6) + expect(await lines.count()).toBe(3) }) test('with other features', async () => { const div = page.locator('#with-other-features + div') expect(await getClassList(div)).toContain('line-numbers-mode') const lines = div.locator('code > span') - expect(await lines.count()).toBe(6) + expect(await lines.count()).toBe(3) expect(await getClassList(lines.nth(0))).toContain('highlighted') }) }) @@ -216,10 +216,10 @@ describe('Code Groups', () => { // blocks const blocks = div.locator('.blocks > div') - expect(await blocks.nth(0).locator('code > span').count()).toBe(22) + expect(await blocks.nth(0).locator('code > span').count()).toBe(11) expect(await getClassList(blocks.nth(1))).toContain('line-numbers-mode') expect(await getClassList(blocks.nth(1))).toContain('language-ts') - expect(await blocks.nth(1).locator('code > span').count()).toBe(6) + expect(await blocks.nth(1).locator('code > span').count()).toBe(3) expect( await getClassList(blocks.nth(1).locator('code > span').nth(0)) ).toContain('highlighted') diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 6a6f35fa..fd9466e4 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -9,7 +9,15 @@ export default defineConfig({ cleanUrls: true, markdown: { - math: true + math: true, + codeTransformers: [ + // We use `[!!code` in demo to prevent transformation, here we revert it back. + { + postprocess(code) { + return code.replace(/\[\!\!code/g, '[!code') + } + } + ] }, sitemap: { diff --git a/docs/.vitepress/theme/AdComponent.vue b/docs/.vitepress/theme/AdComponent.vue deleted file mode 100644 index 15fc4d2e..00000000 --- a/docs/.vitepress/theme/AdComponent.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - diff --git a/docs/.vitepress/theme/documate.vue b/docs/.vitepress/theme/documate.vue deleted file mode 100644 index d89e2f40..00000000 --- a/docs/.vitepress/theme/documate.vue +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts deleted file mode 100644 index 8c9aecc6..00000000 --- a/docs/.vitepress/theme/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// .vitepress/theme/index.js -import { h } from 'vue' -import DefaultTheme from 'vitepress/theme' -import AdComponent from './AdComponent.vue' - -export default { - ...DefaultTheme, - Layout() { - return h(DefaultTheme.Layout, null, { - 'doc-before': () => h(AdComponent) - }) - } -} diff --git a/docs/guide/extending-default-theme.md b/docs/guide/extending-default-theme.md index dcbe66ad..b7b29bde 100644 --- a/docs/guide/extending-default-theme.md +++ b/docs/guide/extending-default-theme.md @@ -116,7 +116,7 @@ import DefaultTheme from 'vitepress/theme' export default { extends: DefaultTheme, - async enhanceApp({ app }) { + enhanceApp({ app }) { // register your custom global components app.component('MyGlobalComponent' /* ... */) } diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index b557c7ff..a2541bd4 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -68,7 +68,7 @@ $ npx vitepress init ``` ```sh [pnpm] -$ pnpm dlx vitepress init +$ pnpm vitepress init ``` ```sh [bun] diff --git a/docs/guide/markdown.md b/docs/guide/markdown.md index 3756235d..8cd9d4ed 100644 --- a/docs/guide/markdown.md +++ b/docs/guide/markdown.md @@ -80,7 +80,7 @@ For more details, see [Frontmatter](../reference/frontmatter-config). **Input** -``` +```md | Tables | Are | Cool | | ------------- | :-----------: | ----: | | col 3 is | right-aligned | $1600 | @@ -108,7 +108,7 @@ For more details, see [Frontmatter](../reference/frontmatter-config). :tada: :100: -A [list of all emojis](https://github.com/markdown-it/markdown-it-emoji/blob/master/lib/data/full.json) is available. +A [list of all emojis](https://github.com/markdown-it/markdown-it-emoji/blob/master/lib/data/full.mjs) is available. ## Table of Contents @@ -265,7 +265,7 @@ Wraps in a
]*(style=".*?")/ - const preRE = /^/ + await options?.shikijiSetup?.(highlighter) + + const transformers: ShikijiTransformer[] = [ + transformerNotationDiff(), + transformerNotationFocus({ + classActiveLine: 'has-focus', + classActivePre: 'has-focused-lines' + }), + transformerNotationHighlight(), + transformerNotationErrorLevel(), + { + name: 'vitepress:add-class', + pre(node) { + addClassToHast(node, 'vp-code') + } + }, + { + name: 'vitepress:clean-up', + pre(node) { + delete node.properties.tabindex + delete node.properties.style + } + } + ] + const vueRE = /-vue$/ const lineNoStartRE = /=(\d*)/ const lineNoRE = /:(no-)?line-numbers(=\d*)?$/ @@ -102,7 +113,7 @@ export async function highlight( if (lang) { const langLoaded = highlighter.getLoadedLanguages().includes(lang as any) - if (!langLoaded && !['ansi', 'plaintext', 'txt', 'text'].includes(lang)) { + if (!langLoaded && !isPlainLang(lang) && !isSpecialLang(lang)) { logger.warn( c.yellow( `\nThe language '${lang}' is not loaded, falling back to '${ @@ -115,16 +126,6 @@ export async function highlight( } const lineOptions = attrsToLines(attrs) - const cleanup = (str: string) => { - return str - .replace( - preRE, - (_, attributes) => - `` - ) - .replace(styleRE, (_, style) => _.replace(style, '')) - } - const mustaches = new Map() const removeMustache = (s: string) => { @@ -155,24 +156,30 @@ export async function highlight( str = removeMustache(str).trimEnd() - const codeToHtml = (theme: IThemeRegistration) => { - const res = - lang === 'ansi' - ? highlighter.ansiToHtml(str, { - lineOptions, - theme: getThemeName(theme) - }) - : highlighter.codeToHtml(str, { - lang, - lineOptions, - theme: getThemeName(theme) - }) - return fillEmptyHighlightedLine(cleanup(restoreMustache(res))) - } + const highlighted = highlighter.codeToHtml(str, { + lang, + transformers: [ + ...transformers, + transformerCompactLineOptions(lineOptions), + { + name: 'vitepress:v-pre', + pre(node) { + if (vPre) node.properties['v-pre'] = '' + } + }, + ...userTransformers + ], + meta: { + __raw: attrs + }, + ...(typeof theme === 'string' || 'name' in theme + ? { theme } + : { + themes: theme, + defaultColor: false + }) + }) - if (hasSingleTheme) return codeToHtml(theme) - const dark = addClass(codeToHtml(theme.dark), 'vp-code-dark', 'pre') - const light = addClass(codeToHtml(theme.light), 'vp-code-light', 'pre') - return dark + light + return fillEmptyHighlightedLine(restoreMustache(highlighted)) } } diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 6cfc02f6..c079dad6 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -152,7 +152,8 @@ export async function createVitePressPlugin( site.themeConfig?.search?.provider === 'algolia' || !!site.themeConfig?.algolia, // legacy __CARBON__: !!site.themeConfig?.carbonAds, - __ASSETS_DIR__: JSON.stringify(siteConfig.assetsDir) + __ASSETS_DIR__: JSON.stringify(siteConfig.assetsDir), + __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: !!process.env.DEBUG }, optimizeDeps: { // force include vue to avoid duplicated copies when linked + optimized diff --git a/src/node/plugins/dynamicRoutesPlugin.ts b/src/node/plugins/dynamicRoutesPlugin.ts index 2807d3ff..e42e8c13 100644 --- a/src/node/plugins/dynamicRoutesPlugin.ts +++ b/src/node/plugins/dynamicRoutesPlugin.ts @@ -119,7 +119,7 @@ export const dynamicRoutesPlugin = async ( // inject raw content // this is intended for integration with CMS - // we use a speical injection syntax so the content is rendered as + // we use a special injection syntax so the content is rendered as // static local content instead of included as runtime data. if (content) { baseContent = baseContent.replace(//, content) diff --git a/src/node/siteConfig.ts b/src/node/siteConfig.ts index 56c0592c..74174280 100644 --- a/src/node/siteConfig.ts +++ b/src/node/siteConfig.ts @@ -147,6 +147,15 @@ export interface UserConfig */ useWebFonts?: boolean + /** + * This option allows you to configure the concurrency of the build. + * A lower number will reduce the memory usage but will increase the build time. + * + * @experimental + * @default 64 + */ + buildConcurrency?: number + /** * @experimental * @@ -240,4 +249,5 @@ export interface SiteConfig } logger: Logger userConfig: UserConfig + buildConcurrency: number } diff --git a/src/shared/shared.ts b/src/shared/shared.ts index c69f7277..9dd05e34 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -113,6 +113,10 @@ export function createTitle(siteData: SiteData, pageData: PageData): string { const templateString = createTitleTemplate(siteData.title, template) + if (title === templateString.slice(3)) { + return title + } + return `${title}${templateString}` } diff --git a/template/markdown-examples.md b/template/markdown-examples.md index 8e55eb8a..3ea9aa9f 100644 --- a/template/markdown-examples.md +++ b/template/markdown-examples.md @@ -4,11 +4,11 @@ This page demonstrates some of the built-in markdown extensions provided by Vite ## Syntax Highlighting -VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting: +VitePress provides Syntax Highlighting powered by [Shikiji](https://github.com/antfu/shikiji), with additional features like line-highlighting: **Input** -```` +````md ```js{4} export default { data () { diff --git a/tsconfig.json b/tsconfig.json index b780a0df..a69d45e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,12 @@ "jsx": "preserve", "lib": ["esnext", "dom", "dom.iterable"] }, - "exclude": ["**/node_modules/**", "**/dist/**", "template"] + "exclude": [ + "**/node_modules/**", + "**/dist/**", + "template", + "bin", + "docs/snippets", + "scripts" + ] } diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 94dfb95c..c89551b0 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -345,6 +345,7 @@ export namespace DefaultTheme { desc?: string links?: SocialLink[] sponsor?: string + actionText?: string } // outline -------------------------------------------------------------------