Skip to content

Commit

Permalink
feat: upgrade markdown-it types to v14 (#3772)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Apr 11, 2024
1 parent 74b725a commit d3dd4bc
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 70 deletions.
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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",
Expand All @@ -120,13 +120,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",
Expand Down Expand Up @@ -221,6 +221,10 @@
},
"overrides": {
"ora>string-width": "^5"
},
"patchedDependencies": {
"@types/markdown-it@14.0.0": "patches/@types__markdown-it@14.0.0.patch",
"markdown-it-anchor@8.6.7": "patches/markdown-it-anchor@8.6.7.patch"
}
}
}
13 changes: 13 additions & 0 deletions patches/@types__markdown-it@14.0.0.patch
Original file line number Diff line number Diff line change
@@ -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",
29 changes: 29 additions & 0 deletions patches/markdown-it-anchor@8.6.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/types/index.d.ts b/types/index.d.ts
index 7c94aae194faa66ca006ace98cdb0dee82a3e471..0377cace7c4a9653d4ecf963babffd4bd68494b0 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1,10 +1,10 @@
-import MarkdownIt = require('markdown-it');
-import Token = require('markdown-it/lib/token');
-import State = require('markdown-it/lib/rules_core/state_core');
+import MarkdownIt from 'markdown-it';
+import Token from 'markdown-it/lib/token.mjs';
+import StateCore from 'markdown-it/lib/rules_core/state_core.mjs';

declare namespace anchor {
- export type RenderHref = (slug: string, state: State) => string;
- export type RenderAttrs = (slug: string, state: State) => Record<string, string | number>;
+ export type RenderHref = (slug: string, state: StateCore) => string;
+ export type RenderAttrs = (slug: string, state: StateCore) => Record<string, string | number>;

export interface PermalinkOptions {
class?: string,
@@ -37,7 +37,7 @@ declare namespace anchor {
placement?: 'before' | 'after'
}

- export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: State, index: number) => void;
+ export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: StateCore, index: number) => void;

export interface AnchorInfo {
slug: string;
122 changes: 66 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/node/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ 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 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,
Expand Down Expand Up @@ -47,7 +48,7 @@ export type ThemeOptions =
dark: ThemeRegistrationAny | BuiltinTheme
}

export interface MarkdownOptions extends MarkdownIt.Options {
export interface MarkdownOptions extends Options {
/* ==================== General Options ==================== */

/**
Expand Down
4 changes: 2 additions & 2 deletions src/node/markdown/plugins/containers.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/node/markdown/plugins/snippet.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -98,7 +98,7 @@ function findRegion(lines: Array<string>, 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]
Expand Down

0 comments on commit d3dd4bc

Please sign in to comment.