@md-plugins/md-plugin-image 0.1.0-alpha.27 → 0.1.0-alpha.29
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/dist/index.d.mts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.mjs +19 -4
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
declare const imagePlugin: (md: MarkdownIt, { imageClass }?: {
|
|
4
|
-
imageClass?: string | undefined;
|
|
5
|
-
}) => void;
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
6
2
|
|
|
7
3
|
interface ImagePluginOptions {
|
|
8
4
|
/**
|
|
@@ -13,4 +9,6 @@ interface ImagePluginOptions {
|
|
|
13
9
|
imageClass?: string;
|
|
14
10
|
}
|
|
15
11
|
|
|
12
|
+
declare const imagePlugin: PluginWithOptions<ImagePluginOptions>;
|
|
13
|
+
|
|
16
14
|
export { type ImagePluginOptions, imagePlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
declare const imagePlugin: (md: MarkdownIt, { imageClass }?: {
|
|
4
|
-
imageClass?: string | undefined;
|
|
5
|
-
}) => void;
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
6
2
|
|
|
7
3
|
interface ImagePluginOptions {
|
|
8
4
|
/**
|
|
@@ -13,4 +9,6 @@ interface ImagePluginOptions {
|
|
|
13
9
|
imageClass?: string;
|
|
14
10
|
}
|
|
15
11
|
|
|
12
|
+
declare const imagePlugin: PluginWithOptions<ImagePluginOptions>;
|
|
13
|
+
|
|
16
14
|
export { type ImagePluginOptions, imagePlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
function resolvePluginOptions(options, key, defaults) {
|
|
2
|
+
if (options && typeof options === "object" && key in options) {
|
|
3
|
+
return { ...defaults, ...options[key] };
|
|
4
|
+
}
|
|
5
|
+
return { ...defaults, ...options };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const DEFAULT_IMAGE_PLUGIN_OPTIONS = {
|
|
9
|
+
imageClass: "markdown-image"
|
|
10
|
+
};
|
|
11
|
+
const imagePlugin = (md, options) => {
|
|
12
|
+
const { imageClass } = resolvePluginOptions(
|
|
13
|
+
options,
|
|
14
|
+
"imagePlugin",
|
|
15
|
+
DEFAULT_IMAGE_PLUGIN_OPTIONS
|
|
16
|
+
);
|
|
2
17
|
const originalImageRender = md.renderer.rules.image;
|
|
3
|
-
md.renderer.rules.image = (tokens, idx,
|
|
18
|
+
md.renderer.rules.image = (tokens, idx, options2, env, self) => {
|
|
4
19
|
const token = tokens[idx];
|
|
5
20
|
if (!token) {
|
|
6
|
-
return self.renderToken(tokens, idx,
|
|
21
|
+
return self.renderToken(tokens, idx, options2);
|
|
7
22
|
}
|
|
8
23
|
let content = token.content;
|
|
9
24
|
const widthMatch = content.match(/width="(\d+)"/);
|
|
@@ -38,7 +53,7 @@ const imagePlugin = (md, { imageClass = "markdown-image" } = {}) => {
|
|
|
38
53
|
}
|
|
39
54
|
});
|
|
40
55
|
}
|
|
41
|
-
return originalImageRender ? originalImageRender(tokens, idx,
|
|
56
|
+
return originalImageRender ? originalImageRender(tokens, idx, options2, env, self) : self.renderToken(tokens, idx, options2);
|
|
42
57
|
};
|
|
43
58
|
};
|
|
44
59
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/md-plugin-image",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.29",
|
|
4
4
|
"description": "A markdown-it plugin for handling images.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"markdown-it": "^14.1.0",
|
|
37
37
|
"@types/markdown-it": "^14.1.2",
|
|
38
|
-
"@md-plugins/shared": "0.1.0-alpha.
|
|
38
|
+
"@md-plugins/shared": "0.1.0-alpha.29"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"markdown-it": "^14.1.0"
|