remark-inline-svg-flex 0.3.7 → 0.3.9
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/.github/workflows/release.yml +3 -0
- package/README.md +10 -8
- package/dist/cjs/plugin.js +7 -5
- package/dist/plugin.js +7 -5
- package/package.json +8 -11
|
@@ -6,6 +6,8 @@ on:
|
|
|
6
6
|
- main
|
|
7
7
|
paths:
|
|
8
8
|
- package.json
|
|
9
|
+
- src/**
|
|
10
|
+
- .github/workflows/**
|
|
9
11
|
|
|
10
12
|
jobs:
|
|
11
13
|
release:
|
|
@@ -43,6 +45,7 @@ jobs:
|
|
|
43
45
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
44
46
|
run: |
|
|
45
47
|
npm ci
|
|
48
|
+
npm run tests
|
|
46
49
|
npm run build
|
|
47
50
|
git config user.name "github-actions"
|
|
48
51
|
git config user.email "github-actions@github.com"
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/remark-inline-svg-flex)
|
|
7
7
|
[](https://github.com/gass-git/remark-inline-svg-flex/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution, wrappers and
|
|
9
|
+
Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution, HTML wrappers and more.
|
|
10
10
|
|
|
11
11
|
- [remark-inline-svg-flex](#remark-inline-svg-flex)
|
|
12
12
|
- [Features](#features)
|
|
@@ -24,7 +24,7 @@ Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring cust
|
|
|
24
24
|
### ✔️ Robust and customizable path resolution
|
|
25
25
|
|
|
26
26
|
- If the SVG path is absolute, it is used as-is.
|
|
27
|
-
- If the path is relative and assetsDir is defined, it is resolved relative to
|
|
27
|
+
- If the path is relative and `assetsDir` is defined, it is resolved relative to the `assetsDir` directory.
|
|
28
28
|
- Otherwise, the path is resolved relative to the Markdown file’s location.
|
|
29
29
|
|
|
30
30
|
### ✔️ Custom HTML wrapper support
|
|
@@ -61,21 +61,19 @@ This is a test markdown document.
|
|
|
61
61
|

|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
And our module `example.js` looks as the one below
|
|
65
|
-
the markdown directory path to `process()` so that the plugin can resolve relative
|
|
66
|
-
paths correctly.
|
|
64
|
+
And our module `example.js` looks as the one below (it is recommended to pass the markdown directory `path` to `process()` so that the plugin can resolve relative paths correctly).
|
|
67
65
|
|
|
68
66
|
```js
|
|
69
67
|
import { remark } from 'remark';
|
|
70
68
|
import { readFile } from 'node:fs/promises';
|
|
71
69
|
import { remarkInlineSvg } from 'remark-inline-svg-flex';
|
|
72
70
|
|
|
73
|
-
const markdown = await readFile(
|
|
71
|
+
const markdown = await readFile(path, { encoding: 'utf8' });
|
|
74
72
|
|
|
75
73
|
return await remark()
|
|
76
74
|
.use(remarkParse)
|
|
77
75
|
.use(remarkInlineSvg)
|
|
78
|
-
.process({ value: markdown, path:
|
|
76
|
+
.process({ value: markdown, path: path });
|
|
79
77
|
```
|
|
80
78
|
|
|
81
79
|
Now running `node example.js` yields:
|
|
@@ -86,7 +84,9 @@ Now running `node example.js` yields:
|
|
|
86
84
|
This is a test markdown document.
|
|
87
85
|
|
|
88
86
|
<figure class="inline-svg">
|
|
89
|
-
<svg
|
|
87
|
+
<svg width="800" height="800" fill="none" viewBox="0 0 16 16">
|
|
88
|
+
...
|
|
89
|
+
</svg>
|
|
90
90
|
</figure>
|
|
91
91
|
```
|
|
92
92
|
|
|
@@ -124,6 +124,8 @@ The SVG's are optimized by default. Disable it by setting it to `false`.
|
|
|
124
124
|
|
|
125
125
|
## SVGO configuration
|
|
126
126
|
|
|
127
|
+
SVGO is configured to use the [default preset](https://svgo.dev/docs/preset-default/) of plugins and the [removeXMLNS](https://svgo.dev/docs/plugins/removeXMLNS/) plugin.
|
|
128
|
+
|
|
127
129
|
```
|
|
128
130
|
{ plugins: ['preset-default', 'removeXMLNS'] }
|
|
129
131
|
```
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -26,12 +26,14 @@ const remarkInlineSvg = (consumerOptions = {}) => {
|
|
|
26
26
|
if (!node.url?.endsWith(options.suffix) || !parent)
|
|
27
27
|
return;
|
|
28
28
|
try {
|
|
29
|
-
const svgPath = resolvePath(options.assetsDir, node, node_path_1.default.dirname(file.history[0]));
|
|
29
|
+
const svgPath = resolvePath(options.assetsDir, node, file.history[0] && node_path_1.default.dirname(file.history[0]));
|
|
30
30
|
const svgString = processSvg(svgPath, options.svgo);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (typeof i === 'number') {
|
|
32
|
+
parent.children[i] = {
|
|
33
|
+
type: 'html',
|
|
34
|
+
value: options.wrapper ? wrap(svgString, options.wrapper) : svgString,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
39
|
console.warn(error);
|
package/dist/plugin.js
CHANGED
|
@@ -24,12 +24,14 @@ const remarkInlineSvg = (consumerOptions = {}) => {
|
|
|
24
24
|
if (!node.url?.endsWith(options.suffix) || !parent)
|
|
25
25
|
return;
|
|
26
26
|
try {
|
|
27
|
-
const svgPath = resolvePath(options.assetsDir, node, path.dirname(file.history[0]));
|
|
27
|
+
const svgPath = resolvePath(options.assetsDir, node, file.history[0] && path.dirname(file.history[0]));
|
|
28
28
|
const svgString = processSvg(svgPath, options.svgo);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (typeof i === 'number') {
|
|
30
|
+
parent.children[i] = {
|
|
31
|
+
type: 'html',
|
|
32
|
+
value: options.wrapper ? wrap(svgString, options.wrapper) : svgString,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
catch (error) {
|
|
35
37
|
console.warn(error);
|
package/package.json
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remark-inline-svg-flex",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.9",
|
|
4
|
+
"description": "Customizable Remark plugin to inline and optimize SVGs with SVGO, with robust path resolution.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"rehype",
|
|
8
|
-
"plugin",
|
|
9
|
-
"rehype-plugin",
|
|
6
|
+
"remark",
|
|
10
7
|
"inline",
|
|
11
8
|
"svg",
|
|
9
|
+
"svgo",
|
|
12
10
|
"image",
|
|
13
11
|
"img",
|
|
14
12
|
"html"
|
|
15
13
|
],
|
|
16
|
-
"homepage": "https://github.com/gass-git/remark-inline-svg-flex#readme",
|
|
17
14
|
"bugs": {
|
|
18
15
|
"url": "https://github.com/gass-git/remark-inline-svg-flex/issues"
|
|
19
16
|
},
|
|
@@ -26,12 +23,12 @@
|
|
|
26
23
|
"type": "module",
|
|
27
24
|
"main": "./dist/cjs/index.js",
|
|
28
25
|
"module": "./dist/index.js",
|
|
29
|
-
"types": "./dist/
|
|
26
|
+
"types": "./dist/types.d.ts",
|
|
30
27
|
"exports": {
|
|
31
28
|
".": {
|
|
32
29
|
"import": "./dist/index.js",
|
|
33
30
|
"require": "./dist/cjs/index.js",
|
|
34
|
-
"types": "./dist/
|
|
31
|
+
"types": "./dist/types.d.ts"
|
|
35
32
|
}
|
|
36
33
|
},
|
|
37
34
|
"scripts": {
|
|
@@ -48,11 +45,11 @@
|
|
|
48
45
|
"rimraf": "^6.1.3",
|
|
49
46
|
"typescript": "^5.9.3",
|
|
50
47
|
"unified": "^11.0.5",
|
|
48
|
+
"vfile": "^6.0.3",
|
|
51
49
|
"vitest": "^4.1.0"
|
|
52
50
|
},
|
|
53
51
|
"dependencies": {
|
|
54
52
|
"svgo": "^4.0.1",
|
|
55
|
-
"unist-util-visit": "^5.1.0"
|
|
56
|
-
"vfile": "^6.0.3"
|
|
53
|
+
"unist-util-visit": "^5.1.0"
|
|
57
54
|
}
|
|
58
55
|
}
|