@md-plugins/md-plugin-image 0.1.0-alpha.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024-present, Jeff Galbraith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @md-plugins/md-plugin-image
2
+
3
+ A **Markdown-It** plugin that enhances image rendering by adding customizable CSS classes. This allows for consistent styling and seamless integration into design systems, making it easy to apply specific layouts or effects to images.
4
+
5
+ ## Features
6
+
7
+ - Adds a customizable CSS class to `<img>` elements.
8
+ - Supports a default class that can be overridden via plugin options.
9
+ - Enhances image styling and layout consistency.
10
+
11
+ ## Installation
12
+
13
+ Install the plugin via your preferred package manager:
14
+
15
+ ```bash
16
+ # With npm:
17
+ npm install @md-plugins/md-plugin-image
18
+ # Or with Yarn:
19
+ yarn add @md-plugins/md-plugin-image
20
+ # Or with pnpm:
21
+ pnpm add @md-plugins/md-plugin-image
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Basic Setup
27
+
28
+ ```js
29
+ import MarkdownIt from 'markdown-it';
30
+ import { imagePlugin } from '@md-plugins/md-plugin-image';
31
+
32
+ const md = new MarkdownIt();
33
+ md.use(imagePlugin, {
34
+ imageClass: 'custom-image-class',
35
+ });
36
+
37
+ const markdownContent = `
38
+ ![Alt text](example.jpg)
39
+ `;
40
+
41
+ const renderedOutput = md.render(markdownContent);
42
+
43
+ console.log('Rendered Output:', renderedOutput);
44
+ ```
45
+
46
+ ### Example Output
47
+
48
+ The rendered output will include the specified CSS class:
49
+
50
+ ```html
51
+ <img src="example.jpg" alt="Alt text" class="custom-image-class" />
52
+ ```
53
+
54
+ ## Options
55
+
56
+ The `md-plugin-image` plugin supports the following options:
57
+
58
+ | Option | Type | Default | Description |
59
+ | ---------- | ------ | ---------------- | -------------------------------------- |
60
+ | imageClass | string | 'markdown-image' | CSS class to apply to all `<img>` tags |
61
+
62
+ ## Testing
63
+
64
+ Run the tests to ensure the plugin behaves as expected:
65
+
66
+ ```bash
67
+ pnpm test
68
+ ```
69
+
70
+ ## License
71
+
72
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
@@ -0,0 +1,16 @@
1
+ import MarkdownIt from 'markdown-it';
2
+
3
+ declare const imagePlugin: (md: MarkdownIt, { imageClass }?: {
4
+ imageClass?: string | undefined;
5
+ }) => void;
6
+
7
+ interface ImagePluginOptions {
8
+ /**
9
+ * The class for the image
10
+ *
11
+ * @default 'markdown-image'
12
+ */
13
+ imageClass?: string;
14
+ }
15
+
16
+ export { type ImagePluginOptions, imagePlugin };
@@ -0,0 +1,16 @@
1
+ import MarkdownIt from 'markdown-it';
2
+
3
+ declare const imagePlugin: (md: MarkdownIt, { imageClass }?: {
4
+ imageClass?: string | undefined;
5
+ }) => void;
6
+
7
+ interface ImagePluginOptions {
8
+ /**
9
+ * The class for the image
10
+ *
11
+ * @default 'markdown-image'
12
+ */
13
+ imageClass?: string;
14
+ }
15
+
16
+ export { type ImagePluginOptions, imagePlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,26 @@
1
+ const imagePlugin = (md, { imageClass = "markdown-image" } = {}) => {
2
+ const originalImageRender = md.renderer.rules.image;
3
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
4
+ const token = tokens[idx];
5
+ if (!token) {
6
+ return self.renderToken(tokens, idx, options);
7
+ }
8
+ const existingClass = token.attrGet("class") || "";
9
+ const combinedClass = [existingClass, imageClass].filter(Boolean).join(" ");
10
+ token.attrSet("class", combinedClass);
11
+ if (token.content) {
12
+ const altIndex = token.attrIndex("alt");
13
+ if (altIndex >= 0 && token.attrs) {
14
+ const altValue = token.attrs[altIndex][1];
15
+ if (!altValue) {
16
+ token.attrs[altIndex][1] = token.content;
17
+ }
18
+ } else {
19
+ token.attrPush(["alt", token.content]);
20
+ }
21
+ }
22
+ return originalImageRender ? originalImageRender(tokens, idx, options, env, self) : self.renderToken(tokens, idx, options);
23
+ };
24
+ };
25
+
26
+ export { imagePlugin };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@md-plugins/md-plugin-image",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "A markdown-it plugin for handling images.",
5
+ "keywords": [
6
+ "markdown-it",
7
+ "quasarframework",
8
+ "vue",
9
+ "types"
10
+ ],
11
+ "homepage": "https://github.com/md-plugins",
12
+ "bugs": {
13
+ "url": "https://github.com/md-plugins/md-plugins/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/md-plugins/md-plugins.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "hawkeye64 <galbraith64@gmail.com>",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "import": {
25
+ "types": "./dist/index.d.mts",
26
+ "default": "./dist/index.mjs"
27
+ }
28
+ }
29
+ },
30
+ "module": "./dist/index.mjs",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "./dist"
34
+ ],
35
+ "dependencies": {
36
+ "@types/markdown-it": "^14.1.2",
37
+ "markdown-it": "^14.1.0",
38
+ "@md-plugins/shared": "0.1.0-alpha.1"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "unbuild",
45
+ "clean": "rm -rf dist",
46
+ "test": "vitest"
47
+ }
48
+ }