@md-plugins/md-plugin-image 0.1.0-alpha.9 → 0.1.0-beta.1
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/README.md +9 -5
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +23 -8
- package/package.json +15 -17
package/README.md
CHANGED
|
@@ -13,12 +13,12 @@ A **Markdown-It** plugin that enhances image rendering by adding customizable CS
|
|
|
13
13
|
Install the plugin via your preferred package manager:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
#
|
|
17
|
-
npm install @md-plugins/md-plugin-image
|
|
18
|
-
# Or with Yarn:
|
|
19
|
-
yarn add @md-plugins/md-plugin-image
|
|
20
|
-
# Or with pnpm:
|
|
16
|
+
# with pnpm:
|
|
21
17
|
pnpm add @md-plugins/md-plugin-image
|
|
18
|
+
# with Yarn:
|
|
19
|
+
yarn add @md-plugins/md-plugin-image
|
|
20
|
+
# with npm:
|
|
21
|
+
npm install @md-plugins/md-plugin-image
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
@@ -67,6 +67,10 @@ Run the tests to ensure the plugin behaves as expected:
|
|
|
67
67
|
pnpm test
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/md-plugins/image/overview) for the latest information.
|
|
73
|
+
|
|
70
74
|
## License
|
|
71
75
|
|
|
72
76
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
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,7 @@ interface ImagePluginOptions {
|
|
|
13
9
|
imageClass?: string;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
declare const imagePlugin: PluginWithOptions<ImagePluginOptions>;
|
|
13
|
+
|
|
14
|
+
export { imagePlugin };
|
|
15
|
+
export type { ImagePluginOptions };
|
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,7 @@ interface ImagePluginOptions {
|
|
|
13
9
|
imageClass?: string;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
declare const imagePlugin: PluginWithOptions<ImagePluginOptions>;
|
|
13
|
+
|
|
14
|
+
export { imagePlugin };
|
|
15
|
+
export type { ImagePluginOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
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+)"/);
|
|
10
25
|
const heightMatch = content.match(/height="(\d+)"/);
|
|
11
|
-
if (widthMatch) {
|
|
26
|
+
if (widthMatch && widthMatch.length > 1) {
|
|
12
27
|
token.attrSet("width", widthMatch[1]);
|
|
13
28
|
content = content.replace(widthMatch[0], "").trim();
|
|
14
29
|
}
|
|
15
|
-
if (heightMatch) {
|
|
30
|
+
if (heightMatch && heightMatch.length > 1) {
|
|
16
31
|
token.attrSet("height", heightMatch[1]);
|
|
17
32
|
content = content.replace(heightMatch[0], "").trim();
|
|
18
33
|
}
|
|
19
34
|
if (content) {
|
|
20
35
|
const altIndex = token.attrIndex("alt");
|
|
21
|
-
if (altIndex >= 0 && token.attrs) {
|
|
36
|
+
if (altIndex >= 0 && token.attrs && token.attrs[altIndex] && token.attrs[altIndex].length > 1) {
|
|
22
37
|
const altValue = token.attrs[altIndex][1];
|
|
23
|
-
if (!altValue) {
|
|
38
|
+
if (!altValue && altIndex) {
|
|
24
39
|
token.attrs[altIndex][1] = content;
|
|
25
40
|
}
|
|
26
41
|
} else {
|
|
@@ -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,24 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/md-plugin-image",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "A markdown-it plugin for handling images.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
7
7
|
"quasarframework",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"types",
|
|
9
|
+
"vue"
|
|
10
10
|
],
|
|
11
11
|
"homepage": "https://github.com/md-plugins",
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/md-plugins/md-plugins/issues"
|
|
14
14
|
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "hawkeye64 <galbraith64@gmail.com>",
|
|
15
17
|
"repository": {
|
|
16
18
|
"type": "git",
|
|
17
19
|
"url": "git+https://github.com/md-plugins/md-plugins.git"
|
|
18
20
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
+
"files": [
|
|
22
|
+
"./dist"
|
|
23
|
+
],
|
|
21
24
|
"type": "module",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
22
27
|
"exports": {
|
|
23
28
|
".": {
|
|
24
29
|
"import": {
|
|
@@ -27,24 +32,17 @@
|
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"files": [
|
|
33
|
-
"./dist"
|
|
34
|
-
],
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"markdown-it": "^14.1.0",
|
|
37
|
-
"@md-plugins/shared": "0.1.0-alpha.9"
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@types/markdown-it": "^14.1.2"
|
|
39
|
+
"@types/markdown-it": "^14.1.2",
|
|
40
|
+
"markdown-it": "^14.1.1",
|
|
41
|
+
"@md-plugins/shared": "0.1.0-beta.1"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"markdown-it": "^14.1.0"
|
|
44
45
|
},
|
|
45
|
-
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
47
|
-
},
|
|
48
46
|
"scripts": {
|
|
49
47
|
"build": "unbuild",
|
|
50
48
|
"clean": "rm -rf dist/ node_modules/",
|