From c9c1c7ec85c87f1a26455e5d860b552c96be198a Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Wed, 10 Apr 2024 10:37:17 +0800 Subject: [PATCH] feat: upgrade markdown-it types to v14 --- package.json | 19 ++-- patches/@types__markdown-it@14.0.0.patch | 13 +++ pnpm-lock.yaml | 118 ++++++++++++----------- src/node/markdown/markdown.ts | 8 +- src/node/markdown/plugins/containers.ts | 4 +- src/node/markdown/plugins/snippet.ts | 4 +- 6 files changed, 95 insertions(+), 71 deletions(-) create mode 100644 patches/@types__markdown-it@14.0.0.patch diff --git a/package.json b/package.json index d5bace23..171bfb7e 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "@docsearch/js": "^3.6.0", "@shikijs/core": "^1.2.4", "@shikijs/transformers": "^1.2.4", - "@types/markdown-it": "^13.0.7", + "@types/markdown-it": "^14.0.0", "@vitejs/plugin-vue": "^5.0.4", "@vue/devtools-api": "^7.0.25", "@vueuse/core": "^10.9.0", @@ -126,13 +126,13 @@ }, "devDependencies": { "@clack/prompts": "^0.7.0", - "@mdit-vue/plugin-component": "2.0.0", - "@mdit-vue/plugin-frontmatter": "2.0.0", - "@mdit-vue/plugin-headers": "2.0.0", - "@mdit-vue/plugin-sfc": "2.0.0", - "@mdit-vue/plugin-title": "2.0.0", - "@mdit-vue/plugin-toc": "2.0.0", - "@mdit-vue/shared": "2.0.0", + "@mdit-vue/plugin-component": "2.1.0", + "@mdit-vue/plugin-frontmatter": "2.1.0", + "@mdit-vue/plugin-headers": "2.1.0", + "@mdit-vue/plugin-sfc": "2.1.0", + "@mdit-vue/plugin-title": "2.1.0", + "@mdit-vue/plugin-toc": "2.1.0", + "@mdit-vue/shared": "2.1.0", "@polka/compression": "1.0.0-next.25", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-commonjs": "^25.0.7", @@ -221,6 +221,9 @@ "search-insights", "postcss" ] + }, + "patchedDependencies": { + "@types/markdown-it@14.0.0": "patches/@types__markdown-it@14.0.0.patch" } } } diff --git a/patches/@types__markdown-it@14.0.0.patch b/patches/@types__markdown-it@14.0.0.patch new file mode 100644 index 00000000..e397a526 --- /dev/null +++ b/patches/@types__markdown-it@14.0.0.patch @@ -0,0 +1,13 @@ +diff --git a/package.json b/package.json +index 46d7bfb79a36d8090d98d1ea1e36216137e00072..7bc1e8be5f1c5b74f52f7fa08935d2df3d19d3e2 100644 +--- a/package.json ++++ b/package.json +@@ -27,7 +27,7 @@ + } + ], + "main": "", +- "types": "index.d.ts", ++ "types": "index.d.mts", + "exports": { + ".": { + "import": "./index.d.mts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 17d2dc75..74d8f0c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: ora>string-width: ^5 +patchedDependencies: + '@types/markdown-it@14.0.0': + hash: 324uktmxmvfeckydcv3tuzbvze + path: patches/@types__markdown-it@14.0.0.patch + importers: .: @@ -24,8 +29,8 @@ importers: specifier: ^1.2.4 version: 1.2.4 '@types/markdown-it': - specifier: ^13.0.7 - version: 13.0.7 + specifier: ^14.0.0 + version: 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) '@vitejs/plugin-vue': specifier: ^5.0.4 version: 5.0.4(vite@5.2.8)(vue@3.4.21) @@ -61,26 +66,26 @@ importers: specifier: ^0.7.0 version: 0.7.0 '@mdit-vue/plugin-component': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/plugin-frontmatter': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/plugin-headers': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/plugin-sfc': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/plugin-title': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/plugin-toc': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@mdit-vue/shared': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.1.0 + version: 2.1.0 '@polka/compression': specifier: 1.0.0-next.25 version: 1.0.0-next.25 @@ -191,7 +196,7 @@ importers: version: 14.1.0 markdown-it-anchor: specifier: ^8.6.7 - version: 8.6.7(@types/markdown-it@13.0.7)(markdown-it@14.1.0) + version: 8.6.7(@types/markdown-it@14.0.0)(markdown-it@14.1.0) markdown-it-attrs: specifier: ^4.1.6 version: 4.1.6(markdown-it@14.1.0) @@ -827,67 +832,67 @@ packages: - supports-color dev: true - /@mdit-vue/plugin-component@2.0.0: - resolution: {integrity: sha512-cTRxlocav/+mfgDcp0P2z/gWuWBez+iNuN4D+b74LpX4AR6UAx2ZvWtCrUZ8VXrO4eCt1/G0YC/Af7mpIb3aoQ==} + /@mdit-vue/plugin-component@2.1.0: + resolution: {integrity: sha512-C3y7/hB90WcCpuxw+Z7uWmF3+NJpjv89PI8EVdxFJMFUfdX9JGBAkW34UA9+JdQSx7ARVeXgcb06zkD5z37cbw==} dependencies: - '@types/markdown-it': 13.0.7 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/plugin-frontmatter@2.0.0: - resolution: {integrity: sha512-/LrT6E60QI4XV4mqx3J87hqYXlR7ZyMvndmftR2RGz7cRAwa/xL+kyFLlgrMxkBIKitOShKa3LS/9Ov9b0fU+g==} + /@mdit-vue/plugin-frontmatter@2.1.0: + resolution: {integrity: sha512-vVDjrv1RZorGo1yW7PZg7/dwRupSBzMt8YE8mmM+TMA0NtFEhYfWdHj8vWgkXm1ZJUugmXheL6SxJzo6fz6uHA==} dependencies: - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) gray-matter: 4.0.3 markdown-it: 14.1.0 dev: true - /@mdit-vue/plugin-headers@2.0.0: - resolution: {integrity: sha512-ITMMPCnLEYHHgj3XEUL2l75jsNn8guxNqr26YrMSi1f5zcgq4XVy1LIvfwvJ1puqM6Cc5v4BHk3oAyorAi7l1A==} + /@mdit-vue/plugin-headers@2.1.0: + resolution: {integrity: sha512-vau2AtVIN+nqjlMrvYOpz2toBkJJGUcqJY48Mlo33YybBYNDRCBrX/1VFWJ++B3IeJpdFFMLwhZvRN5tsuhPhQ==} dependencies: - '@mdit-vue/shared': 2.0.0 - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/shared': 2.1.0 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/plugin-sfc@2.0.0: - resolution: {integrity: sha512-OXrMXOyk0iwdIou2jRoIHIbjskwghkO14C9/OjgVHXSSX+iM/WQ4l4yi1aWmNlbQNjtP8IXcVAyJB9K0DFYmLg==} + /@mdit-vue/plugin-sfc@2.1.0: + resolution: {integrity: sha512-7M07z3sADHQXwf9CuOXQBK4+Ga+wxnyTNrwsuk0knnvXRO7l6N6yL5sPgzgz67e4UBsqDwsxgWzTgsnzmv6OMg==} dependencies: - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/plugin-title@2.0.0: - resolution: {integrity: sha512-eqBoETPVkMXNLvwFshz/A2+Cz81VB5HEkXDm0tt6RBW/rTvnoWmGJ1Z+mvcjR5ck5W4nYdIyT68oHxX2JI2M4g==} + /@mdit-vue/plugin-title@2.1.0: + resolution: {integrity: sha512-16KmXwMnWxDwj6CelA1Fyf12/OYvkA2c2MN1iFAdJQnK7wOSPcUscdVO7nxverThuPQLENt/8500/AJqjH4/3Q==} dependencies: - '@mdit-vue/shared': 2.0.0 - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/shared': 2.1.0 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/plugin-toc@2.0.0: - resolution: {integrity: sha512-PKQ8sZna3D5chTnt2lxL+ddpyXd++6Nyc0l8VXCeDgStlySQwiP9jaLeeC88oqY4BtRu4cAmILmxDrvuX0Rrdg==} + /@mdit-vue/plugin-toc@2.1.0: + resolution: {integrity: sha512-CUVIHELx73yPypYKvnG+6cwjudUCq5vqXOCb3HfFQOICVXk9Y5W0MFOnGBcyt2JxY4D1dUWusj3YT4o0MDm/Eg==} dependencies: - '@mdit-vue/shared': 2.0.0 - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/shared': 2.1.0 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/shared@2.0.0: - resolution: {integrity: sha512-PdxpQpbyTazeo2JT87qms6RPZIzyJd+gwuB+1jSwLDI7+0u5g79y2XgTAbZromSVgY2f3UU5HWdwaLbV9w4uOw==} + /@mdit-vue/shared@2.1.0: + resolution: {integrity: sha512-eLPdmaB9f7VGjC6AzA5Q2pOzj1s5uJMtF+925SQTjlZIzlJbv1KFwjcO57dlr8aOzF1XrWm8j8nB1qYlecW4Ig==} dependencies: - '@mdit-vue/types': 2.0.0 - '@types/markdown-it': 13.0.7 + '@mdit-vue/types': 2.1.0 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true - /@mdit-vue/types@2.0.0: - resolution: {integrity: sha512-1BeEB+DbtmDMUAfvbNUj5Hso8cSl2sBVK2iTyOMAqhfDVLdh+/9+D0JmQHaCeUk/vuJoMhOwbweZvh55wHxm4w==} + /@mdit-vue/types@2.1.0: + resolution: {integrity: sha512-TMBB/BQWVvwtpBdWD75rkZx4ZphQ6MN0O4QB2Bc0oI5PC2uE57QerhNxdRZ7cvBHE2iY2C+BUNUziCfJbjIRRA==} dev: true /@nodelib/fs.scandir@2.1.5: @@ -1219,26 +1224,27 @@ packages: /@types/markdown-it-attrs@4.1.3: resolution: {integrity: sha512-1JsseFdHD6rQHsPcy4W3xx/whxvZ09Z+CqPpnOtrGtpmkFW07N11q7oM383//LtoKv54yn+HGnk6r4ZHUTHJVg==} dependencies: - '@types/markdown-it': 13.0.7 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) dev: true /@types/markdown-it-container@2.0.10: resolution: {integrity: sha512-zv+YxrlSYRq51e9kzm3orv4OvF4U79Ll1OyplNXr00o4ZC/8PukJk/jEWH7CnsMtrSWZlyv0czhz42jm9J4uLw==} dependencies: - '@types/markdown-it': 13.0.7 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) dev: true /@types/markdown-it-emoji@2.0.5: resolution: {integrity: sha512-iJLsmCNpSWKtV6Ia3mLSjcXJPEt7ubGG342z+hGvYx++TpM19oTUrJcI7XjbOqRQ+W2UQ323E7B0eCLwlgT/9g==} dependencies: - '@types/markdown-it': 13.0.7 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) dev: true - /@types/markdown-it@13.0.7: - resolution: {integrity: sha512-U/CBi2YUUcTHBt5tjO2r5QV/x0Po6nsYwQU4Y04fBS6vfoImaiZ6f8bi3CjTCxBPQSO1LMyUqkByzi8AidyxfA==} + /@types/markdown-it@14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze): + resolution: {integrity: sha512-2rStaAqMaLQNfo9mg2HNlley75jUTAkZKqlk3pxDSgaFk44zd+CAVpczpoh6/RtOzfUtwpEyD6lsHWUfKbVSDg==} dependencies: '@types/linkify-it': 3.0.5 '@types/mdurl': 1.0.5 + patched: true /@types/mdurl@1.0.5: resolution: {integrity: sha512-6L6VymKTzYSrEf4Nev4Xa1LCHKrlTlYCBMTlQKFuddo1CvQcE52I0mwfOJayueUC7MJuXOeHTcIU683lzd0cUA==} @@ -3308,13 +3314,13 @@ packages: resolution: {integrity: sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==} dev: false - /markdown-it-anchor@8.6.7(@types/markdown-it@13.0.7)(markdown-it@14.1.0): + /markdown-it-anchor@8.6.7(@types/markdown-it@14.0.0)(markdown-it@14.1.0): resolution: {integrity: sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==} peerDependencies: '@types/markdown-it': '*' markdown-it: '*' dependencies: - '@types/markdown-it': 13.0.7 + '@types/markdown-it': 14.0.0(patch_hash=324uktmxmvfeckydcv3tuzbvze) markdown-it: 14.1.0 dev: true diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 9554ad7f..24df22d0 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -15,9 +15,11 @@ import { titlePlugin } from '@mdit-vue/plugin-title' import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc' import { slugify } from '@mdit-vue/shared' import MarkdownIt from 'markdown-it' +import type { Options } from 'markdown-it' +import type StateCore from 'markdown-it/lib/rules_core/state_core.mjs' import anchorPlugin from 'markdown-it-anchor' import attrsPlugin from 'markdown-it-attrs' -// @ts-ignore +// @ts-expect-error: types of markdown-it-emoji are not up-to-date import { full as emojiPlugin } from 'markdown-it-emoji' import type { BuiltinTheme, @@ -47,7 +49,7 @@ export type ThemeOptions = dark: ThemeRegistrationAny | BuiltinTheme } -export interface MarkdownOptions extends MarkdownIt.Options { +export interface MarkdownOptions extends Options { /* ==================== General Options ==================== */ /** @@ -238,7 +240,7 @@ export const createMarkdownRenderer = async ( slugify, permalink: anchorPlugin.permalink.linkInsideHeader({ symbol: '​', - renderAttrs: (slug, state) => { + renderAttrs: (slug, state: StateCore) => { // Find `heading_open` with the id identical to slug const idx = state.tokens.findIndex((token) => { const attrs = token.attrs diff --git a/src/node/markdown/plugins/containers.ts b/src/node/markdown/plugins/containers.ts index 5008850b..c9338b93 100644 --- a/src/node/markdown/plugins/containers.ts +++ b/src/node/markdown/plugins/containers.ts @@ -1,6 +1,6 @@ import type MarkdownIt from 'markdown-it' -import type { RenderRule } from 'markdown-it/lib/renderer' -import type Token from 'markdown-it/lib/token' +import type { RenderRule } from 'markdown-it/lib/renderer.mjs' +import type Token from 'markdown-it/lib/token.mjs' import container from 'markdown-it-container' import { nanoid } from 'nanoid' import { diff --git a/src/node/markdown/plugins/snippet.ts b/src/node/markdown/plugins/snippet.ts index c41dbc93..108ea8eb 100644 --- a/src/node/markdown/plugins/snippet.ts +++ b/src/node/markdown/plugins/snippet.ts @@ -1,6 +1,6 @@ import fs from 'fs-extra' import type MarkdownIt from 'markdown-it' -import type { RuleBlock } from 'markdown-it/lib/parser_block' +import type ParserBlock from 'markdown-it/lib/parser_block.mjs' import path from 'path' import type { MarkdownEnv } from '../../shared' @@ -98,7 +98,7 @@ function findRegion(lines: Array, regionName: string) { } export const snippetPlugin = (md: MarkdownIt, srcDir: string) => { - const parser: RuleBlock = (state, startLine, endLine, silent) => { + const parser: ParserBlock.RuleBlock = (state, startLine, endLine, silent) => { const CH = '<'.charCodeAt(0) const pos = state.bMarks[startLine] + state.tShift[startLine] const max = state.eMarks[startLine]