Skip to content

Commit ab6cbbf

Browse files
authored
Merge pull request #8 from 0gust1/fix/config_side-effect_bug
Fix/config side effect bug
2 parents 1058dcd + e868e43 commit ab6cbbf

File tree

10 files changed

+1272
-342
lines changed

10 files changed

+1272
-342
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
with:
1818
node-version: 20
1919
- run: npm ci
20-
#- run: npm test
20+
- name: Unit tests
21+
run: npm test
2122

2223
publish-npm:
2324
needs: build

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# mdsvex-enhanced-images
22
[![NPM Downloads](https://img.shields.io/npm/dt/%40lzinga%2Fmdsvex-enhanced-images)](https://www.npmjs.com/package/@lzinga/mdsvex-enhanced-images)
33

4-
Allows you to:
5-
- use relative urls to images from the markdown file while also using the enhanced:img library from @sveltejs/enhanced-img.
6-
- add css classes and extra attributes to images in markdown
7-
- add imagetools directives to images in markdown
4+
This plugin allows you to:
5+
- use relative urls to images from the markdown file while also using the `enhanced:img` library from `@sveltejs/enhanced-img`.
6+
- add CSS class names and extra attributes (`loading`, `fetchpriority`, and `decoding`) to images directly in markdown (image by image) or through the plugin configuration (to all images).
7+
- add imagetools directives to images in markdown (image by image) or through the plugin configuration (to all images).
88

9-
Thanks to https://github.com/mattjennings/mdsvex-relative-images for the inspiration.
9+
Special thanks to https://github.com/mattjennings/mdsvex-relative-images, for the inspiration.
10+
11+
Feel free to open a PR or an issue if you have any suggestions or feature requests!
1012

1113
## Usage
1214

13-
Install the package
14-
```
15-
npm install --save-dev mdsvex-enhanced-images
15+
### Installation
16+
17+
```bash
18+
npm install --save-dev @lzinga/mdsvex-enhanced-images
1619
```
1720

21+
(or the equivalent pnmp / yarn / bun commands)
22+
23+
### Configuration
24+
1825
Configure the package in your mdsvex config.
26+
1927
```ts
2028
import enhancedImage from 'mdsvex-enhanced-images';
2129

@@ -53,6 +61,7 @@ const config = {
5361
```
5462

5563
Now you can add images like
64+
5665
```markdown
5766
### Image With Space Local Folder
5867
![Image With Space Local Folder](./img%20with%20space.png)

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const RE_SCRIPT_START =
55
/<script(?:\s+?[a-zA-z]+(=(?:["']){0,1}[a-zA-Z0-9]+(?:["']){0,1}){0,1})*\s*?>/;
66
const RE_SRC = /src\s*=\s*"(.+?)"/;
77

8-
export default function enhancedImage(options = {}) {
8+
export default function enhancedImage(config = {}) {
99
return function transformer(tree) {
1010
let scripts = "";
1111
visit(tree, "image", (node) => {
@@ -15,7 +15,7 @@ export default function enhancedImage(options = {}) {
1515
combinedClassesAttrStr,
1616
combinedAttributesStr,
1717
combinedDirectivesUrlParams,
18-
} = processAttributesAndConfig(node.url, options);
18+
} = processAttributesAndConfig(node.url, config);
1919

2020
// Now, clean possible search params from the node.url
2121
// They've been processed and are now in the result of processAttributesAndConfig call

0 commit comments

Comments
 (0)