vuepress-plugin-md-power 1.0.0-rc.95 → 1.0.0-rc.97
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/lib/node/index.js +59 -2
- package/package.json +5 -4
package/lib/node/index.js
CHANGED
|
@@ -1337,10 +1337,10 @@ function getFileIcon(fileName) {
|
|
|
1337
1337
|
if (!name)
|
|
1338
1338
|
return defaultFileIcon;
|
|
1339
1339
|
if (name in FileIcons) {
|
|
1340
|
-
const
|
|
1340
|
+
const path5 = FileIcons[name];
|
|
1341
1341
|
return {
|
|
1342
1342
|
name: name.includes(":") ? name.split(":")[1] : name,
|
|
1343
|
-
svg: makeSVGIcon(
|
|
1343
|
+
svg: makeSVGIcon(path5)
|
|
1344
1344
|
};
|
|
1345
1345
|
}
|
|
1346
1346
|
return defaultFileIcon;
|
|
@@ -1437,6 +1437,62 @@ async function fileTreePlugin(app, md) {
|
|
|
1437
1437
|
await app.writeTemp(styleFilepath, "");
|
|
1438
1438
|
}
|
|
1439
1439
|
|
|
1440
|
+
// src/node/features/imageSize.ts
|
|
1441
|
+
import { isLinkExternal } from "@vuepress/helper";
|
|
1442
|
+
import { fs as fs3, path as path4 } from "@vuepress/utils";
|
|
1443
|
+
import imageSize from "image-size";
|
|
1444
|
+
function imageSizePlugin(app, md) {
|
|
1445
|
+
if (!app.env.isBuild)
|
|
1446
|
+
return;
|
|
1447
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1448
|
+
const imageRule = md.renderer.rules.image;
|
|
1449
|
+
md.renderer.rules.image = (tokens, idx, options, env, self) => {
|
|
1450
|
+
if (!env.filePathRelative || !env.filePath)
|
|
1451
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1452
|
+
const token = tokens[idx];
|
|
1453
|
+
const src = token.attrGet("src");
|
|
1454
|
+
if (!src || src.startsWith("data:") || isLinkExternal(src))
|
|
1455
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1456
|
+
const width = token.attrGet("width");
|
|
1457
|
+
const height = token.attrGet("height");
|
|
1458
|
+
if (width && height)
|
|
1459
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1460
|
+
const filepath2 = resolveImageUrl(src, env);
|
|
1461
|
+
if (!cache.has(filepath2)) {
|
|
1462
|
+
if (!filepath2 || !fs3.existsSync(filepath2))
|
|
1463
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1464
|
+
const { width: w, height: h } = imageSize(filepath2);
|
|
1465
|
+
if (!w || !h)
|
|
1466
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1467
|
+
cache.set(filepath2, { width: w, height: h });
|
|
1468
|
+
}
|
|
1469
|
+
const { width: originalWidth, height: originalHeight } = cache.get(filepath2);
|
|
1470
|
+
const ratio = originalWidth / originalHeight;
|
|
1471
|
+
if (width && !height) {
|
|
1472
|
+
const w = Number.parseInt(width, 10);
|
|
1473
|
+
token.attrSet("width", `${w}`);
|
|
1474
|
+
token.attrSet("height", `${Math.round(w / ratio)}`);
|
|
1475
|
+
} else if (height && !width) {
|
|
1476
|
+
const h = Number.parseInt(height, 10);
|
|
1477
|
+
token.attrSet("width", `${Math.round(h * ratio)}`);
|
|
1478
|
+
token.attrSet("height", `${h}`);
|
|
1479
|
+
} else {
|
|
1480
|
+
token.attrSet("width", `${originalWidth}`);
|
|
1481
|
+
token.attrSet("height", `${originalHeight}`);
|
|
1482
|
+
}
|
|
1483
|
+
return imageRule(tokens, idx, options, env, self);
|
|
1484
|
+
};
|
|
1485
|
+
function resolveImageUrl(src, env) {
|
|
1486
|
+
if (src[0] === "/")
|
|
1487
|
+
return app.dir.public(src.slice(1));
|
|
1488
|
+
if (env.filePathRelative)
|
|
1489
|
+
return app.dir.source(path4.join(path4.dirname(env.filePathRelative), src));
|
|
1490
|
+
if (env.filePath)
|
|
1491
|
+
return path4.resolve(env.filePath, src);
|
|
1492
|
+
return "";
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1440
1496
|
// src/node/plugin.ts
|
|
1441
1497
|
function markdownPowerPlugin(options = {}) {
|
|
1442
1498
|
return (app) => {
|
|
@@ -1456,6 +1512,7 @@ function markdownPowerPlugin(options = {}) {
|
|
|
1456
1512
|
}
|
|
1457
1513
|
},
|
|
1458
1514
|
extendsMarkdown: async (md, app2) => {
|
|
1515
|
+
imageSizePlugin(app2, md);
|
|
1459
1516
|
if (options.caniuse) {
|
|
1460
1517
|
const caniuse = options.caniuse === true ? {} : options.caniuse;
|
|
1461
1518
|
md.use(caniusePlugin, caniuse);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vuepress-plugin-md-power",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.97",
|
|
5
5
|
"description": "The Plugin for VuePress 2 - markdown power",
|
|
6
6
|
"author": "pengzhanbo <volodymyr@foxmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@vuepress/helper": "2.0.0-rc.42",
|
|
38
38
|
"@vueuse/core": "^11.0.3",
|
|
39
|
+
"image-size": "^1.1.1",
|
|
39
40
|
"markdown-it-container": "^4.0.0",
|
|
40
41
|
"nanoid": "^5.0.7",
|
|
41
|
-
"shiki": "^1.16.
|
|
42
|
-
"tm-grammars": "^1.17.
|
|
42
|
+
"shiki": "^1.16.2",
|
|
43
|
+
"tm-grammars": "^1.17.18",
|
|
43
44
|
"tm-themes": "^1.8.1",
|
|
44
|
-
"vue": "^3.5.
|
|
45
|
+
"vue": "^3.5.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/markdown-it": "^14.1.2"
|