You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allows you to use relative urls to images from the markdown file while also using the enhanced:img library from @sveltejs/enhanced-img.
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
5
8
6
-
Thanks to https://github.com/mattjennings/mdsvex-relative-imagesas I used it as a base for this. It could probably be a lot more dynamic and allow custom configurations, but for now. This is all I needed. If you have a recommended change please do a pull request.
9
+
Thanks to https://github.com/mattjennings/mdsvex-relative-images for the inspiration.
7
10
11
+
## Usage
8
12
9
-
# Usage
10
13
Install the package
11
14
```
12
-
npm i @lzinga/mdsvex-enhanced-images
15
+
npm install --save-dev mdsvex-enhanced-images
13
16
```
14
17
15
18
Configure the package in your mdsvex config.
@@ -22,7 +25,24 @@ const config = {
22
25
preprocess: [
23
26
mdsvex({
24
27
extensions: ['.md'],
25
-
remarkPlugins: [enhancedImage]
28
+
remarkPlugins: [[
29
+
enhancedImage,
30
+
{
31
+
// Optional: attributes to add to **all** `img` tags
32
+
attributes: {
33
+
fetchpriority: "auto", // browser's default
34
+
loading: "eager", // browser's default
35
+
decoding: "auto", // browser's default
36
+
class: "test-decoration test-shadow"// add classes to all images
37
+
},
38
+
// Optional: imagetools directives to add to **all** `img` tags
39
+
// see https://github.com/JonasKruckenberg/imagetools/blob/main/docs/directives.md#format
40
+
imagetoolsDirectives:{
41
+
tint: "rgba(10,33,127)",
42
+
blur: 10,
43
+
}
44
+
}
45
+
]]
26
46
})
27
47
],
28
48
kit: {
@@ -44,7 +64,22 @@ Now you can add images like
44
64

45
65
```
46
66
67
+
You can also individually add css classes and extra attribute to images:
68
+
69
+
```markdown
70
+
### Image with css classes:
71
+

72
+
73
+
### Image with more attributes (here, loading=lazy):
74
+

75
+
76
+
### Image with imagetools directives
77
+
78
+

79
+
```
80
+
47
81
and in the page the images get replaced with the component like so.
82
+
48
83
```html
49
84
<enhanced:imgsrc={importedImage}alt="Image With Space Local Folder"></enhanced:img>
0 commit comments