@vuepress/markdown 2.0.0-rc.31 → 2.0.0-rc.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +51 -52
  2. package/dist/index.js +31 -38
  3. package/package.json +14 -16
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import MarkdownIt, { Options, PluginWithOptions } from "markdown-it";
1
+ import { Env, MarkdownIt, MarkdownItOptions } from "markdown-it";
2
2
  import { ComponentPluginOptions, componentPlugin } from "@mdit-vue/plugin-component";
3
3
  import { FrontmatterPluginOptions, frontmatterPlugin } from "@mdit-vue/plugin-frontmatter";
4
4
  import { HeadersPluginOptions, headersPlugin } from "@mdit-vue/plugin-headers";
@@ -6,13 +6,20 @@ import { MarkdownSfcBlocks, SfcPluginOptions, sfcPlugin } from "@mdit-vue/plugin
6
6
  import { titlePlugin } from "@mdit-vue/plugin-title";
7
7
  import { TocPluginOptions, tocPlugin } from "@mdit-vue/plugin-toc";
8
8
  import anchorPlugin from "markdown-it-anchor";
9
- import { Options as Options$1, full as emojiPlugin } from "markdown-it-emoji";
10
9
  import { PageFrontmatter, PageHeader } from "@vuepress/shared";
11
- import { MarkdownItEnv } from "@mdit-vue/types";
12
- //#region src/plugins/anchorPlugin.d.ts
10
+ import { MarkdownItPlugin } from "@mdit-vue/types";
11
+ interface MarkdownItAnchorEnv {
12
+ slugs: Record<string, true>;
13
+ }
14
+ declare module 'markdown-it' {
15
+ interface Env {
16
+ /**
17
+ * Slugs registered by markdown-it-anchor
18
+ */
19
+ markdownItAnchor?: MarkdownItAnchorEnv;
20
+ }
21
+ }
13
22
  type AnchorPluginOptions = anchorPlugin.AnchorOptions;
14
- //#endregion
15
- //#region src/plugins/assetsPlugin/assetsPlugin.d.ts
16
23
  interface AssetsPluginOptions {
17
24
  /**
18
25
  * Whether to prepend base to absolute path
@@ -38,21 +45,20 @@ interface AssetsPluginOptions {
38
45
  /**
39
46
  * Plugin to handle assets links
40
47
  */
41
- declare const assetsPlugin: PluginWithOptions<AssetsPluginOptions>;
42
- //#endregion
43
- //#region src/plugins/emojiPlugin.d.ts
44
- type EmojiPluginOptions = Options$1;
45
- //#endregion
46
- //#region src/plugins/importCodePlugin/importCodePlugin.d.ts
48
+ export declare const assetsPlugin: MarkdownItPlugin<AssetsPluginOptions>;
49
+ interface EmojiPluginOptions {
50
+ defs: Record<string, string>;
51
+ enabled: string[];
52
+ shortcuts: Record<string, string[] | string>;
53
+ }
54
+ export declare const emojiPlugin: MarkdownItPlugin<Partial<EmojiPluginOptions>>;
47
55
  interface ImportCodePluginOptions {
48
56
  /**
49
57
  * A function to handle the import path
50
58
  */
51
59
  handleImportPath?: (str: string) => string;
52
60
  }
53
- declare const importCodePlugin: PluginWithOptions<ImportCodePluginOptions>;
54
- //#endregion
55
- //#region src/plugins/linksPlugin/linksPlugin.d.ts
61
+ export declare const importCodePlugin: MarkdownItPlugin<ImportCodePluginOptions>;
56
62
  interface LinksPluginOptions {
57
63
  /**
58
64
  * Additional attributes for external links
@@ -85,9 +91,7 @@ interface LinksPluginOptions {
85
91
  * - internal links: convert `<a>` tag into internalTag
86
92
  * - external links: add extra attrs
87
93
  */
88
- declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
89
- //#endregion
90
- //#region src/plugins/vPrePlugin/vPrePlugin.d.ts
94
+ export declare const linksPlugin: MarkdownItPlugin<LinksPluginOptions>;
91
95
  interface VPrePluginOptions {
92
96
  /**
93
97
  * Add `v-pre` directive to `<pre>` tag of code block or not
@@ -101,11 +105,9 @@ interface VPrePluginOptions {
101
105
  /**
102
106
  * v-pre plugin
103
107
  */
104
- declare const vPrePlugin: PluginWithOptions<VPrePluginOptions>;
105
- //#endregion
106
- //#region src/types.d.ts
108
+ export declare const vPrePlugin: MarkdownItPlugin<VPrePluginOptions>;
107
109
  type Markdown = MarkdownIt;
108
- interface MarkdownOptions extends Options {
110
+ interface MarkdownOptions extends MarkdownItOptions {
109
111
  anchor?: AnchorPluginOptions | false;
110
112
  assets?: AssetsPluginOptions | false;
111
113
  component?: false;
@@ -138,48 +140,45 @@ interface MarkdownLink {
138
140
  relative: string;
139
141
  absolute: string | null;
140
142
  }
143
+ declare module 'markdown-it' {
144
+ interface Env {
145
+ /**
146
+ * Base / publicPath of current site
147
+ */
148
+ base?: string;
149
+ /**
150
+ * Absolute file path of the markdown file
151
+ */
152
+ filePath?: string | null;
153
+ /**
154
+ * Relative file path of the markdown file
155
+ */
156
+ filePathRelative?: string | null;
157
+ /**
158
+ * Imported file that extracted by importCodePlugin
159
+ */
160
+ importedFiles?: string[];
161
+ /**
162
+ * Links that extracted by linksPlugin
163
+ */
164
+ links?: MarkdownLink[];
165
+ }
166
+ }
141
167
  /**
142
168
  * The `env` object to be passed to markdown-it render function
143
- *
144
- * Input some meta data for markdown file parsing and rendering
145
- *
146
- * Output some resources from the markdown file
147
169
  */
148
- interface MarkdownEnv extends MarkdownItEnv {
149
- /**
150
- * Base / publicPath of current site
151
- */
152
- base?: string;
153
- /**
154
- * Absolute file path of the markdown file
155
- */
156
- filePath?: string | null;
157
- /**
158
- * Relative file path of the markdown file
159
- */
160
- filePathRelative?: string | null;
170
+ interface MarkdownEnv extends Env {
161
171
  /**
162
172
  * Frontmatter of the markdown file
163
173
  */
164
174
  frontmatter?: PageFrontmatter;
165
- /**
166
- * Imported file that extracted by importCodePlugin
167
- */
168
- importedFiles?: string[];
169
- /**
170
- * Links that extracted by linksPlugin
171
- */
172
- links?: MarkdownLink[];
173
175
  }
174
176
  /**
175
177
  * Type of `slugify` function
176
178
  */
177
179
  type MarkdownSlugifyFunction = (str: string) => string;
178
- //#endregion
179
- //#region src/markdown.d.ts
180
180
  /**
181
181
  * Create vuepress customized markdown-it instance
182
182
  */
183
- declare const createMarkdown: ({ anchor, assets, code, vPre, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
184
- //#endregion
185
- export { type AnchorPluginOptions, type AssetsPluginOptions, type ComponentPluginOptions, type EmojiPluginOptions, type FrontmatterPluginOptions, type HeadersPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSfcBlocks, type MarkdownSlugifyFunction, type SfcPluginOptions, type TocPluginOptions, type VPrePluginOptions, anchorPlugin, assetsPlugin, componentPlugin, createMarkdown, emojiPlugin, frontmatterPlugin, headersPlugin, importCodePlugin, linksPlugin, sfcPlugin, titlePlugin, tocPlugin, vPrePlugin };
183
+ export declare const createMarkdown: ({ anchor, assets, code, vPre, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
184
+ export { type AnchorPluginOptions, type AssetsPluginOptions, type ComponentPluginOptions, type EmojiPluginOptions, type FrontmatterPluginOptions, type HeadersPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownItAnchorEnv, type MarkdownLink, type MarkdownOptions, type MarkdownSfcBlocks, type MarkdownSlugifyFunction, type SfcPluginOptions, type TocPluginOptions, type VPrePluginOptions, anchorPlugin, componentPlugin, frontmatterPlugin, headersPlugin, sfcPlugin, titlePlugin, tocPlugin };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { slugify } from "@mdit-vue/shared";
2
2
  import { colors, fs, logger, path } from "@vuepress/utils";
3
- import MarkdownIt from "markdown-it";
3
+ import MarkdownIt$1 from "markdown-it";
4
4
  import { componentPlugin } from "@mdit-vue/plugin-component";
5
5
  import { frontmatterPlugin } from "@mdit-vue/plugin-frontmatter";
6
6
  import { headersPlugin } from "@mdit-vue/plugin-headers";
@@ -9,9 +9,9 @@ import { titlePlugin } from "@mdit-vue/plugin-title";
9
9
  import { tocPlugin } from "@mdit-vue/plugin-toc";
10
10
  import anchorPlugin from "markdown-it-anchor";
11
11
  import { decode } from "mdurl";
12
- import { full as emojiPlugin } from "markdown-it-emoji";
12
+ import { full } from "markdown-it-emoji";
13
13
  import { inferRoutePath, isLinkExternal, removeLeadingSlash } from "@vuepress/shared";
14
- //#region src/plugins/assetsPlugin/resolveLink.ts
14
+ // src/plugins/assetsPlugin/resolveLink.ts
15
15
  const resolveLink = (link, { env, absolutePathPrependBase = false, aliasSupport = true }) => {
16
16
  if (link.startsWith("data:")) return link;
17
17
  let resolvedLink = decode(link);
@@ -23,24 +23,23 @@ const resolveLink = (link, { env, absolutePathPrependBase = false, aliasSupport
23
23
  if (absolutePathPrependBase && env.base && link.startsWith("/")) resolvedLink = path.join(env.base, resolvedLink);
24
24
  return resolvedLink;
25
25
  };
26
- //#endregion
27
- //#region src/plugins/assetsPlugin/assetsPlugin.ts
26
+ // src/plugins/assetsPlugin/assetsPlugin.ts
28
27
  /**
29
28
  * Plugin to handle assets links
30
29
  */
31
30
  const assetsPlugin = (md, { absolutePathPrependBase = false, aliasSupport = true } = {}) => {
32
31
  const rawImageRule = md.renderer.rules.image;
33
- md.renderer.rules.image = (tokens, idx, options, env, self) => {
32
+ md.renderer.rules.image = (tokens, idx, options, env = {}, self) => {
34
33
  const token = tokens[idx];
35
34
  const link = token.attrGet("src");
36
- if (link) token.attrSet("src", resolveLink(link, {
35
+ if (link) token.attrSet("src", resolveLink(String(link), {
37
36
  env,
38
37
  absolutePathPrependBase,
39
38
  aliasSupport
40
39
  }));
41
40
  return rawImageRule(tokens, idx, options, env, self);
42
41
  };
43
- const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
42
+ const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env = {}, self) => {
44
43
  tokens[idx].content = tokens[idx].content.replace(/(<(?:img|source|video|audio)\b.*?\bsrc=)(['"])(.*?)\2/gs, (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
45
44
  env,
46
45
  absolutePathPrependBase,
@@ -57,8 +56,9 @@ const assetsPlugin = (md, { absolutePathPrependBase = false, aliasSupport = true
57
56
  md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
58
57
  md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
59
58
  };
60
- //#endregion
61
- //#region src/plugins/importCodePlugin/createImportCodeBlockRule.ts
59
+ // src/plugins/emojiPlugin.ts
60
+ const emojiPlugin = full;
61
+ // src/plugins/importCodePlugin/createImportCodeBlockRule.ts
62
62
  const MIN_LENGTH = 9;
63
63
  const START_CODES = [
64
64
  64,
@@ -100,8 +100,7 @@ const createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (stat
100
100
  state.line = startLine + 1;
101
101
  return true;
102
102
  };
103
- //#endregion
104
- //#region src/plugins/importCodePlugin/resolveImportCode.ts
103
+ // src/plugins/importCodePlugin/resolveImportCode.ts
105
104
  const resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
106
105
  let importFilePath = importPath;
107
106
  if (!path.isAbsolute(importPath)) {
@@ -127,8 +126,7 @@ const resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) =>
127
126
  importCode: fileContent.split("\n").slice(lineStart ? lineStart - 1 : lineStart, lineEnd).join("\n").replace(/\n?$/, "\n")
128
127
  };
129
128
  };
130
- //#endregion
131
- //#region src/plugins/importCodePlugin/importCodePlugin.ts
129
+ // src/plugins/importCodePlugin/importCodePlugin.ts
132
130
  const importCodePlugin = (md, options = {}) => {
133
131
  md.block.ruler.before("fence", "import_code", createImportCodeBlockRule(options), { alt: [
134
132
  "paragraph",
@@ -136,7 +134,7 @@ const importCodePlugin = (md, options = {}) => {
136
134
  "blockquote",
137
135
  "list"
138
136
  ] });
139
- md.renderer.rules.import_code = (tokens, idx, opts, env, slf) => {
137
+ md.renderer.rules.import_code = (tokens, idx, opts, env = {}, slf) => {
140
138
  const token = tokens[idx];
141
139
  const { importFilePath, importCode } = resolveImportCode(token.meta, env);
142
140
  token.content = importCode;
@@ -144,22 +142,22 @@ const importCodePlugin = (md, options = {}) => {
144
142
  return md.renderer.rules.fence(tokens, idx, opts, env, slf);
145
143
  };
146
144
  };
147
- //#endregion
148
- //#region src/plugins/linksPlugin/resolvePaths.ts
145
+ // src/plugins/linksPlugin/resolvePaths.ts
149
146
  /**
150
147
  * Resolve relative and absolute paths according to the `base` and `filePathRelative`
151
148
  */
152
149
  const resolvePaths = (rawPath, base, filePathRelative) => {
153
150
  let absolutePath;
154
151
  let relativePath;
155
- if (rawPath.startsWith("/")) if (rawPath.endsWith(".md")) {
156
- absolutePath = path.join(base, rawPath);
157
- relativePath = removeLeadingSlash(rawPath);
158
- } else {
159
- absolutePath = rawPath;
160
- relativePath = path.relative(base, absolutePath);
161
- }
162
- else if (filePathRelative) {
152
+ if (rawPath.startsWith("/")) {
153
+ if (rawPath.endsWith(".md")) {
154
+ absolutePath = path.join(base, rawPath);
155
+ relativePath = removeLeadingSlash(rawPath);
156
+ } else {
157
+ absolutePath = rawPath;
158
+ relativePath = path.relative(base, absolutePath);
159
+ }
160
+ } else if (filePathRelative) {
163
161
  relativePath = path.join(path.dirname(encodeURI(filePathRelative)), rawPath);
164
162
  absolutePath = path.join(base, relativePath);
165
163
  } else {
@@ -171,8 +169,7 @@ const resolvePaths = (rawPath, base, filePathRelative) => {
171
169
  relativePath
172
170
  };
173
171
  };
174
- //#endregion
175
- //#region src/plugins/linksPlugin/linksPlugin.ts
172
+ // src/plugins/linksPlugin/linksPlugin.ts
176
173
  /**
177
174
  * Process links in markdown file
178
175
  *
@@ -194,7 +191,7 @@ const linksPlugin = (md, options = {}) => {
194
191
  /* istanbul ignore if */
195
192
  if (hrefIndex < 0) return;
196
193
  const hrefAttr = token.attrs[hrefIndex];
197
- const hrefLink = hrefAttr[1];
194
+ const hrefLink = String(hrefAttr[1]);
198
195
  const { base = "/", filePathRelative = null } = env;
199
196
  if (isExternal(hrefLink, env)) {
200
197
  Object.entries(externalAttrs).forEach(([key, val]) => {
@@ -219,11 +216,11 @@ const linksPlugin = (md, options = {}) => {
219
216
  absolute: absolutePath
220
217
  });
221
218
  };
222
- md.renderer.rules.link_open = (tokens, idx, opts, env, self) => {
219
+ md.renderer.rules.link_open = (tokens, idx, opts, env = {}, self) => {
223
220
  handleLinkOpen(tokens, idx, env);
224
221
  return self.renderToken(tokens, idx, opts);
225
222
  };
226
- md.renderer.rules.link_close = (tokens, idx, opts, _env, self) => {
223
+ md.renderer.rules.link_close = (tokens, idx, opts, env, self) => {
227
224
  if (hasOpenInternalLink) {
228
225
  hasOpenInternalLink = false;
229
226
  tokens[idx].tag = internalTag;
@@ -231,8 +228,7 @@ const linksPlugin = (md, options = {}) => {
231
228
  return self.renderToken(tokens, idx, opts);
232
229
  };
233
230
  };
234
- //#endregion
235
- //#region src/plugins/vPrePlugin/resolveVPre.ts
231
+ // src/plugins/vPrePlugin/resolveVPre.ts
236
232
  /**
237
233
  * Resolve the `:v-pre` / `:no-v-pre` mark from token info
238
234
  */
@@ -241,8 +237,7 @@ const resolveVPre = (info) => {
241
237
  if (/:no-v-pre\b/.test(info)) return false;
242
238
  return null;
243
239
  };
244
- //#endregion
245
- //#region src/plugins/vPrePlugin/vPrePlugin.ts
240
+ // src/plugins/vPrePlugin/vPrePlugin.ts
246
241
  /**
247
242
  * v-pre plugin
248
243
  */
@@ -263,13 +258,12 @@ const vPrePlugin = (md, { inline = true, block = true } = {}) => {
263
258
  };
264
259
  }
265
260
  };
266
- //#endregion
267
- //#region src/markdown.ts
261
+ // src/markdown.ts
268
262
  /**
269
263
  * Create vuepress customized markdown-it instance
270
264
  */
271
265
  const createMarkdown = ({ anchor, assets, code, vPre, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify: slugify$1 = slugify, toc, ...markdownItOptions } = {}) => {
272
- const md = MarkdownIt({
266
+ const md = new MarkdownIt$1({
273
267
  ...markdownItOptions,
274
268
  html: true
275
269
  });
@@ -318,5 +312,4 @@ const createMarkdown = ({ anchor, assets, code, vPre, component, emoji, frontmat
318
312
  if (vPre !== false) md.use(vPrePlugin, vPre);
319
313
  return md;
320
314
  };
321
- //#endregion
322
315
  export { anchorPlugin, assetsPlugin, componentPlugin, createMarkdown, emojiPlugin, frontmatterPlugin, headersPlugin, importCodePlugin, linksPlugin, sfcPlugin, titlePlugin, tocPlugin, vPrePlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-rc.31",
3
+ "version": "2.0.0-rc.32",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "markdown",
@@ -31,22 +31,20 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@mdit-vue/plugin-component": "^3.0.2",
35
- "@mdit-vue/plugin-frontmatter": "^3.0.2",
36
- "@mdit-vue/plugin-headers": "^3.0.2",
37
- "@mdit-vue/plugin-sfc": "^3.0.2",
38
- "@mdit-vue/plugin-title": "^3.0.2",
39
- "@mdit-vue/plugin-toc": "^3.0.2",
40
- "@mdit-vue/shared": "^3.0.2",
41
- "@mdit-vue/types": "^3.0.2",
42
- "@types/markdown-it": "^14.1.2",
43
- "@types/markdown-it-emoji": "^3.0.1",
44
- "markdown-it": "^14.3.0",
45
- "markdown-it-anchor": "^9.2.1",
34
+ "@mdit-vue/plugin-component": "^4.0.0",
35
+ "@mdit-vue/plugin-frontmatter": "^4.0.0",
36
+ "@mdit-vue/plugin-headers": "^4.0.0",
37
+ "@mdit-vue/plugin-sfc": "^4.0.0",
38
+ "@mdit-vue/plugin-title": "^4.0.0",
39
+ "@mdit-vue/plugin-toc": "^4.0.0",
40
+ "@mdit-vue/shared": "^4.0.0",
41
+ "@mdit-vue/types": "^4.0.0",
42
+ "@vuepress/shared": "2.0.0-rc.32",
43
+ "@vuepress/utils": "2.0.0-rc.32",
44
+ "markdown-it": "^15.0.3",
45
+ "markdown-it-anchor": "^10.1.0",
46
46
  "markdown-it-emoji": "^3.1.0",
47
- "mdurl": "^2.1.0",
48
- "@vuepress/shared": "2.0.0-rc.31",
49
- "@vuepress/utils": "2.0.0-rc.31"
47
+ "mdurl": "^2.1.0"
50
48
  },
51
49
  "tsdown": {
52
50
  "dts": true,