mirror of https://github.com/vuejs/vitepress
feat: use `markdown-it-async`, remove `synckit` (#4507)
BREAKING CHANGES: markdown-it-async is used instead of markdown-it --------- Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>pull/4530/head
parent
74a0222f9a
commit
80622356f1
@ -0,0 +1,17 @@
|
||||
diff --git a/types/index.d.ts b/types/index.d.ts
|
||||
index 40c25c0be1add8b0fc2c51489c25a423dbc49d2c..807bc1b0e434d660c6a298b1dee1c87935bfac86 100644
|
||||
--- a/types/index.d.ts
|
||||
+++ b/types/index.d.ts
|
||||
@@ -1,10 +1,8 @@
|
||||
import MarkdownIt from 'markdown-it';
|
||||
-import { default as MarkdownItToken } from 'markdown-it/lib/token.mjs';
|
||||
-import { default as MarkdownItState} from 'markdown-it/lib/rules_core/state_core.mjs';
|
||||
+import { default as Token } from 'markdown-it/lib/token.mjs';
|
||||
+import { default as State } from 'markdown-it/lib/rules_core/state_core.mjs';
|
||||
|
||||
declare namespace anchor {
|
||||
- export type Token = MarkdownItToken
|
||||
- export type State = MarkdownItState
|
||||
export type RenderHref = (slug: string, state: State) => string;
|
||||
export type RenderAttrs = (slug: string, state: State) => Record<string, string | number>;
|
||||
|
@ -0,0 +1,47 @@
|
||||
// this file contains node-only types of default theme
|
||||
// (functions starting with _ are node-only)
|
||||
// in most of the cases these will leak to client too
|
||||
// but these can import types from dev deps
|
||||
|
||||
import type { MarkdownItAsync } from 'markdown-it-async'
|
||||
import type { DefaultTheme } from '../../types/default-theme'
|
||||
import type { PageSplitSection } from '../../types/local-search'
|
||||
import type { Awaitable, MarkdownEnv } from './shared'
|
||||
|
||||
declare module '../../types/default-theme.js' {
|
||||
namespace DefaultTheme {
|
||||
interface LocalSearchOptions {
|
||||
/**
|
||||
* Allows transformation of content before indexing (node only)
|
||||
* Return empty string to skip indexing
|
||||
*/
|
||||
_render?: (
|
||||
src: string,
|
||||
env: MarkdownEnv,
|
||||
md: MarkdownItAsync
|
||||
) => Awaitable<string>
|
||||
}
|
||||
|
||||
interface MiniSearchOptions {
|
||||
/**
|
||||
* Overrides the default regex based page splitter.
|
||||
* Supports async generator, making it possible to run in true parallel
|
||||
* (when used along with `node:child_process` or `worker_threads`)
|
||||
* ---
|
||||
* This should be especially useful for scalability reasons.
|
||||
* ---
|
||||
* @param {string} path - absolute path to the markdown source file
|
||||
* @param {string} html - document page rendered as html
|
||||
*/
|
||||
_splitIntoSections?: (
|
||||
path: string,
|
||||
html: string
|
||||
) =>
|
||||
| AsyncGenerator<PageSplitSection>
|
||||
| Generator<PageSplitSection>
|
||||
| Awaitable<PageSplitSection[]>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type { DefaultTheme }
|
@ -1,23 +0,0 @@
|
||||
import {
|
||||
bundledLanguages,
|
||||
type DynamicImportLanguageRegistration,
|
||||
type LanguageRegistration
|
||||
} from 'shiki'
|
||||
import { runAsWorker } from 'synckit'
|
||||
|
||||
async function resolveLang(lang: string) {
|
||||
return (
|
||||
(
|
||||
bundledLanguages as Record<
|
||||
string,
|
||||
DynamicImportLanguageRegistration | undefined
|
||||
>
|
||||
)
|
||||
[lang]?.()
|
||||
.then((m) => m.default) || ([] as LanguageRegistration[])
|
||||
)
|
||||
}
|
||||
|
||||
runAsWorker(resolveLang)
|
||||
|
||||
export type ShikiResolveLang = typeof resolveLang
|
Loading…
Reference in new issue