@vuepress/markdown 2.0.0-rc.0 → 2.0.0-rc.2

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-present, Yuxi (Evan) You
3
+ Copyright (c) 2018-present, VuePress Community
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @vuepress/markdown
2
+
3
+ [![npm](https://badgen.net/npm/v/@vuepress/markdown/next)](https://www.npmjs.com/package/@vuepress/markdown)
4
+ [![license](https://badgen.net/github/license/vuepress/core)](https://github.com/vuepress/core/blob/main/LICENSE)
5
+
6
+ ## Documentation
7
+
8
+ https://v2.vuepress.vuejs.org
9
+
10
+ ## License
11
+
12
+ [MIT](https://github.com/vuepress/core/blob/main/LICENSE)
package/dist/index.d.ts CHANGED
@@ -11,14 +11,18 @@ import { TocPluginOptions } from '@mdit-vue/plugin-toc';
11
11
  export { TocPluginOptions, tocPlugin } from '@mdit-vue/plugin-toc';
12
12
  import anchorPlugin from 'markdown-it-anchor';
13
13
  export { default as anchorPlugin } from 'markdown-it-anchor';
14
- import emojiPlugin from 'markdown-it-emoji';
15
- export { default as emojiPlugin } from 'markdown-it-emoji';
14
+ import { Options } from 'markdown-it-emoji';
15
+ export { full as emojiPlugin } from 'markdown-it-emoji';
16
16
  export { ComponentPluginOptions, componentPlugin } from '@mdit-vue/plugin-component';
17
17
  export { titlePlugin } from '@mdit-vue/plugin-title';
18
18
 
19
19
  type AnchorPluginOptions = anchorPlugin.AnchorOptions;
20
20
 
21
21
  interface AssetsPluginOptions {
22
+ /**
23
+ * Whether to prepend base to absolute path
24
+ */
25
+ absolutePathPrependBase?: boolean;
22
26
  /**
23
27
  * Prefix to add to relative assets links
24
28
  */
@@ -47,7 +51,7 @@ interface CodePluginOptions {
47
51
  *
48
52
  * - Required for `highlightLines`
49
53
  * - Required for `lineNumbers`
50
- * - Required for language display of default theme
54
+ * - Required for title display of default theme
51
55
  */
52
56
  preWrapper?: boolean;
53
57
  /**
@@ -69,7 +73,7 @@ interface CodePluginOptions {
69
73
  */
70
74
  declare const codePlugin: PluginWithOptions<CodePluginOptions>;
71
75
 
72
- type EmojiPluginOptions = emojiPlugin.Options;
76
+ type EmojiPluginOptions = Options;
73
77
 
74
78
  interface ImportCodePluginOptions {
75
79
  /**
@@ -181,4 +185,4 @@ type MarkdownSlugifyFunction = (str: string) => string;
181
185
  */
182
186
  declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
183
187
 
184
- export { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, ImportCodePluginOptions, LinksPluginOptions, Markdown, MarkdownEnv, MarkdownHeader, MarkdownLink, MarkdownOptions, MarkdownSlugifyFunction, assetsPlugin, codePlugin, createMarkdown, importCodePlugin, linksPlugin };
188
+ export { type AnchorPluginOptions, type AssetsPluginOptions, type CodePluginOptions, type EmojiPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSlugifyFunction, assetsPlugin, codePlugin, createMarkdown, importCodePlugin, linksPlugin };
package/dist/index.js CHANGED
@@ -28,7 +28,12 @@ import { default as anchorPlugin } from "markdown-it-anchor";
28
28
  // src/plugins/assetsPlugin/resolveLink.ts
29
29
  import { path } from "@vuepress/utils";
30
30
  import { decode } from "mdurl";
31
- var resolveLink = (link, relativePathPrefix, env, strict = false) => {
31
+ var resolveLink = (link, {
32
+ env,
33
+ absolutePathPrependBase = false,
34
+ relativePathPrefix,
35
+ strict = false
36
+ }) => {
32
37
  if (link.startsWith("data:"))
33
38
  return link;
34
39
  let resolvedLink = decode(link);
@@ -45,40 +50,49 @@ var resolveLink = (link, relativePathPrefix, env, strict = false) => {
45
50
  resolvedLink
46
51
  )}`;
47
52
  }
53
+ if (absolutePathPrependBase && env.base && link.startsWith("/")) {
54
+ resolvedLink = path.join(env.base, resolvedLink);
55
+ }
48
56
  return resolvedLink;
49
57
  };
50
58
 
51
59
  // src/plugins/assetsPlugin/assetsPlugin.ts
52
- var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
60
+ var assetsPlugin = (md, {
61
+ absolutePathPrependBase = false,
62
+ relativePathPrefix = "@source"
63
+ } = {}) => {
53
64
  const rawImageRule = md.renderer.rules.image;
54
65
  md.renderer.rules.image = (tokens, idx, options, env, self) => {
55
66
  const token = tokens[idx];
56
67
  const link = token.attrGet("src");
57
68
  if (link) {
58
- token.attrSet("src", resolveLink(link, relativePathPrefix, env));
69
+ token.attrSet(
70
+ "src",
71
+ resolveLink(link, { env, absolutePathPrependBase, relativePathPrefix })
72
+ );
59
73
  }
60
74
  return rawImageRule(tokens, idx, options, env, self);
61
75
  };
62
76
  const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
63
77
  tokens[idx].content = tokens[idx].content.replace(
64
78
  /(<img\b.*?src=)(['"])([^\2]*?)\2/gs,
65
- (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(
66
- src.trim(),
67
- relativePathPrefix,
79
+ (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
68
80
  env,
69
- true
70
- )}${quote}`
81
+ absolutePathPrependBase,
82
+ relativePathPrefix,
83
+ strict: true
84
+ })}${quote}`
71
85
  ).replace(
72
86
  /(<img\b.*?srcset=)(['"])([^\2]*?)\2/gs,
73
87
  (_, prefix, quote, srcset) => `${prefix}${quote}${srcset.split(",").map(
74
88
  (item) => item.trim().replace(
75
89
  /^([^ ]*?)([ \n].*)?$/,
76
- (_2, url, descriptor = "") => `${resolveLink(
77
- url.trim(),
78
- relativePathPrefix,
90
+ (_2, url, descriptor = "") => `${resolveLink(url.trim(), {
79
91
  env,
80
- true
81
- )}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
92
+ absolutePathPrependBase,
93
+ relativePathPrefix,
94
+ strict: true
95
+ })}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
82
96
  )
83
97
  ).join(", ")}${quote}`
84
98
  );
@@ -90,6 +104,14 @@ var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
90
104
  md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
91
105
  };
92
106
 
107
+ // src/plugins/codePlugin/resolveAttr.ts
108
+ var resolveAttr = (info, attr) => {
109
+ const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`;
110
+ const regex = new RegExp(pattern, "i");
111
+ const match = info.match(regex);
112
+ return match?.groups?.content ?? null;
113
+ };
114
+
93
115
  // src/plugins/codePlugin/resolveHighlightLines.ts
94
116
  var resolveHighlightLines = (info) => {
95
117
  const match = info.match(/{([\d,-]+)}/);
@@ -271,7 +293,8 @@ var codePlugin = (md, {
271
293
  const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
272
294
  result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
273
295
  }
274
- result = `<div class="${languageClass}${useLineNumbers ? " line-numbers-mode" : ""}" data-ext="${language.ext}">${result}</div>`;
296
+ const title = resolveAttr(info, "title") ?? language.ext;
297
+ result = `<div class="${languageClass}${useLineNumbers ? " line-numbers-mode" : ""}" data-ext="${language.ext}" data-title="${title}">${result}</div>`;
275
298
  return result;
276
299
  };
277
300
  if (vPreInline) {
@@ -284,7 +307,7 @@ var codePlugin = (md, {
284
307
  };
285
308
 
286
309
  // src/plugins/emojiPlugin.ts
287
- import emojiPlugin from "markdown-it-emoji";
310
+ import { full as emojiPlugin } from "markdown-it-emoji";
288
311
 
289
312
  // src/plugins/importCodePlugin/createImportCodeBlockRule.ts
290
313
  import { path as path2 } from "@vuepress/utils";
@@ -501,11 +524,10 @@ var createMarkdown = ({
501
524
  md.use(anchorPlugin, {
502
525
  level: [1, 2, 3, 4, 5, 6],
503
526
  slugify,
504
- permalink: anchorPlugin.permalink.ariaHidden({
527
+ permalink: anchorPlugin.permalink.headerLink({
505
528
  class: "header-anchor",
506
- symbol: "#",
507
- space: true,
508
- placement: "before"
529
+ // Add a span inside the link so Safari shows headings in reader view.
530
+ safariReaderFix: true
509
531
  }),
510
532
  ...anchor
511
533
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.2",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -8,11 +8,11 @@
8
8
  ],
9
9
  "homepage": "https://github.com/vuepress",
10
10
  "bugs": {
11
- "url": "https://github.com/vuepress/vuepress-next/issues"
11
+ "url": "https://github.com/vuepress/core/issues"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+https://github.com/vuepress/vuepress-next.git"
15
+ "url": "git+https://github.com/vuepress/core.git"
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "meteorlxy",
@@ -27,22 +27,22 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@mdit-vue/plugin-component": "^1.0.0",
31
- "@mdit-vue/plugin-frontmatter": "^1.0.0",
32
- "@mdit-vue/plugin-headers": "^1.0.0",
33
- "@mdit-vue/plugin-sfc": "^1.0.0",
34
- "@mdit-vue/plugin-title": "^1.0.0",
35
- "@mdit-vue/plugin-toc": "^1.0.0",
36
- "@mdit-vue/shared": "^1.0.0",
37
- "@mdit-vue/types": "^1.0.0",
38
- "@types/markdown-it": "^13.0.6",
30
+ "@mdit-vue/plugin-component": "^2.0.0",
31
+ "@mdit-vue/plugin-frontmatter": "^2.0.0",
32
+ "@mdit-vue/plugin-headers": "^2.0.0",
33
+ "@mdit-vue/plugin-sfc": "^2.0.0",
34
+ "@mdit-vue/plugin-title": "^2.0.0",
35
+ "@mdit-vue/plugin-toc": "^2.0.0",
36
+ "@mdit-vue/shared": "^2.0.0",
37
+ "@mdit-vue/types": "^2.0.0",
38
+ "@types/markdown-it": "^13.0.7",
39
39
  "@types/markdown-it-emoji": "^2.0.4",
40
- "markdown-it": "^13.0.2",
40
+ "markdown-it": "^14.0.0",
41
41
  "markdown-it-anchor": "^8.6.7",
42
- "markdown-it-emoji": "^2.0.2",
43
- "mdurl": "^1.0.1",
44
- "@vuepress/shared": "2.0.0-rc.0",
45
- "@vuepress/utils": "2.0.0-rc.0"
42
+ "markdown-it-emoji": "^3.0.0",
43
+ "mdurl": "^2.0.0",
44
+ "@vuepress/shared": "2.0.0-rc.2",
45
+ "@vuepress/utils": "2.0.0-rc.2"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/mdurl": "^1.0.5"
@@ -62,7 +62,7 @@
62
62
  "outDir": "./dist",
63
63
  "sourcemap": false,
64
64
  "target": "es2022",
65
- "tsconfig": "../tsconfig.dts.json"
65
+ "tsconfig": "../../tsconfig.dts.json"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",