@vuepress/markdown 2.0.0-beta.60 → 2.0.0-beta.62

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 (2) hide show
  1. package/dist/index.js +25 -10
  2. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -28,9 +28,16 @@ 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) => {
31
+ var resolveLink = (link, relativePathPrefix, env, strict = false) => {
32
32
  let resolvedLink = decode(link);
33
- if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
33
+ const isRelativePath = strict ? (
34
+ // in strict mode, only link that starts with `./` or `../` is considered as relative path
35
+ /^\.{1,2}\//.test(link)
36
+ ) : (
37
+ // in non-strict mode, link that does not start with `/` and does not have protocol is considered as relative path
38
+ !link.startsWith("/") && !/[A-z]+:\/\//.test(link)
39
+ );
40
+ if (isRelativePath && env.filePathRelative) {
34
41
  resolvedLink = `${relativePathPrefix}/${path.join(
35
42
  path.dirname(env.filePathRelative),
36
43
  resolvedLink
@@ -56,7 +63,8 @@ var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
56
63
  (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(
57
64
  src.trim(),
58
65
  relativePathPrefix,
59
- env
66
+ env,
67
+ true
60
68
  )}${quote}`
61
69
  ).replace(
62
70
  /(<img\b.*?srcset=)(['"])([^\2]*?)\2/gs,
@@ -66,7 +74,8 @@ var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
66
74
  (_2, url, descriptor = "") => `${resolveLink(
67
75
  url.trim(),
68
76
  relativePathPrefix,
69
- env
77
+ env,
78
+ true
70
79
  )}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
71
80
  )
72
81
  ).join(", ")}${quote}`
@@ -235,7 +244,8 @@ var codePlugin = (md, {
235
244
  const language = resolveLanguage(info);
236
245
  const languageClass = `${options.langPrefix}${language.name}`;
237
246
  const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content);
238
- let result = code.startsWith("<pre") ? code : `<pre class="${languageClass}"><code>${code}</code></pre>`;
247
+ token.attrJoin("class", languageClass);
248
+ let result = code.startsWith("<pre") ? code : `<pre${slf.renderAttrs(token)}><code>${code}</code></pre>`;
239
249
  const useVPre = resolveVPre(info) ?? vPreBlock;
240
250
  if (useVPre) {
241
251
  result = `<pre v-pre${result.slice("<pre".length)}`;
@@ -313,11 +323,14 @@ var createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state,
313
323
  };
314
324
 
315
325
  // src/plugins/importCodePlugin/resolveImportCode.ts
316
- import { fs, path as path3 } from "@vuepress/utils";
326
+ import { colors, fs, logger, path as path3 } from "@vuepress/utils";
317
327
  var resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
318
328
  let importFilePath = importPath;
319
329
  if (!path3.isAbsolute(importPath)) {
320
330
  if (!filePath) {
331
+ logger.error(
332
+ `Import file ${colors.magenta(importPath)} can not be resolved`
333
+ );
321
334
  return {
322
335
  importFilePath: null,
323
336
  importCode: "Error when resolving path"
@@ -326,6 +339,7 @@ var resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
326
339
  importFilePath = path3.resolve(filePath, "..", importPath);
327
340
  }
328
341
  if (!fs.existsSync(importFilePath)) {
342
+ logger.error(`Import file ${colors.magenta(importPath)} not found`);
329
343
  return {
330
344
  importFilePath,
331
345
  importCode: "File not found"
@@ -353,8 +367,8 @@ var importCodePlugin = (md, options = {}) => {
353
367
  const { importFilePath, importCode } = resolveImportCode(token.meta, env);
354
368
  token.content = importCode;
355
369
  if (importFilePath) {
356
- const importedFiles = env.importedFiles || (env.importedFiles = []);
357
- importedFiles.push(importFilePath);
370
+ ;
371
+ (env.importedFiles ?? (env.importedFiles = [])).push(importFilePath);
358
372
  }
359
373
  return md.renderer.rules.fence(tokens, idx, options2, env, slf);
360
374
  };
@@ -380,6 +394,7 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
380
394
  } else {
381
395
  if (filePathRelative) {
382
396
  relativePath = path4.join(
397
+ // file path may contain non-ASCII characters
383
398
  path4.dirname(encodeURI(filePathRelative)),
384
399
  rawPath
385
400
  );
@@ -439,8 +454,7 @@ var linksPlugin = (md, options = {}) => {
439
454
  hasOpenInternalLink = true;
440
455
  }
441
456
  hrefAttr[1] = `${normalizedPath}${rawHash}`;
442
- const links = env.links || (env.links = []);
443
- links.push({
457
+ (env.links ?? (env.links = [])).push({
444
458
  raw: hrefLink,
445
459
  relative: relativePath,
446
460
  absolute: absolutePath
@@ -478,6 +492,7 @@ var createMarkdown = ({
478
492
  } = {}) => {
479
493
  const md = MarkdownIt({
480
494
  ...markdownItOptions,
495
+ // should always enable html option
481
496
  html: true
482
497
  });
483
498
  if (anchor !== false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.60",
3
+ "version": "2.0.0-beta.62",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -27,22 +27,22 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@mdit-vue/plugin-component": "^0.11.2",
31
- "@mdit-vue/plugin-frontmatter": "^0.11.1",
32
- "@mdit-vue/plugin-headers": "^0.11.2",
33
- "@mdit-vue/plugin-sfc": "^0.11.1",
34
- "@mdit-vue/plugin-title": "^0.11.2",
35
- "@mdit-vue/plugin-toc": "^0.11.2",
36
- "@mdit-vue/shared": "^0.11.2",
37
- "@mdit-vue/types": "^0.11.0",
30
+ "@mdit-vue/plugin-component": "^0.12.0",
31
+ "@mdit-vue/plugin-frontmatter": "^0.12.0",
32
+ "@mdit-vue/plugin-headers": "^0.12.0",
33
+ "@mdit-vue/plugin-sfc": "^0.12.0",
34
+ "@mdit-vue/plugin-title": "^0.12.0",
35
+ "@mdit-vue/plugin-toc": "^0.12.0",
36
+ "@mdit-vue/shared": "^0.12.0",
37
+ "@mdit-vue/types": "^0.12.0",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@types/markdown-it-emoji": "^2.0.2",
40
40
  "markdown-it": "^13.0.1",
41
- "markdown-it-anchor": "^8.6.6",
41
+ "markdown-it-anchor": "^8.6.7",
42
42
  "markdown-it-emoji": "^2.0.2",
43
43
  "mdurl": "^1.0.1",
44
- "@vuepress/shared": "2.0.0-beta.60",
45
- "@vuepress/utils": "2.0.0-beta.60"
44
+ "@vuepress/shared": "2.0.0-beta.62",
45
+ "@vuepress/utils": "2.0.0-beta.62"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/mdurl": "^1.0.2"