remark-inline-svg-flex 0.3.8 → 0.4.0

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.
@@ -6,6 +6,7 @@ on:
6
6
  - main
7
7
  paths:
8
8
  - package.json
9
+ - src/**
9
10
 
10
11
  jobs:
11
12
  release:
@@ -37,12 +38,13 @@ jobs:
37
38
  node-version: 24
38
39
  registry-url: https://registry.npmjs.org/
39
40
 
40
- - name: build, publish and release
41
+ - name: test, build, publish and release
41
42
  if: steps.tagcheck.outputs.exists == 'false'
42
43
  env:
43
44
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44
45
  run: |
45
46
  npm ci
47
+ npm run tests
46
48
  npm run build
47
49
  git config user.name "github-actions"
48
50
  git config user.email "github-actions@github.com"
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![version](https://img.shields.io/npm/v/remark-inline-svg-flex.svg?style=flat-square)](https://www.npmjs.com/package/remark-inline-svg-flex)
7
7
  [![MIT License](https://img.shields.io/npm/l/remark-inline-svg-flex.svg?style=flat-square)](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 others.
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 that directory.
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,19 +61,19 @@ This is a test markdown document.
61
61
  ![some svg](some.svg)
62
62
  ```
63
63
 
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).
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).
65
65
 
66
66
  ```js
67
67
  import { remark } from 'remark';
68
68
  import { readFile } from 'node:fs/promises';
69
69
  import { remarkInlineSvg } from 'remark-inline-svg-flex';
70
70
 
71
- const markdown = await readFile(_path, { encoding: 'utf8' });
71
+ const markdown = await readFile(path, { encoding: 'utf8' });
72
72
 
73
73
  return await remark()
74
74
  .use(remarkParse)
75
75
  .use(remarkInlineSvg)
76
- .process({ value: markdown, path: _path });
76
+ .process({ value: markdown, path: path });
77
77
  ```
78
78
 
79
79
  Now running `node example.js` yields:
@@ -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
  ```
@@ -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
- parent.children[i] = {
32
- type: 'html',
33
- value: options.wrapper ? wrap(svgString, options.wrapper) : svgString,
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
- parent.children[i] = {
30
- type: 'html',
31
- value: options.wrapper ? wrap(svgString, options.wrapper) : svgString,
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.8",
4
- "description": "Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution and wrappers.",
3
+ "version": "0.4.0",
4
+ "description": "Customizable Remark plugin to inline and optimize SVGs with SVGO, with robust path resolution.",
5
5
  "keywords": [
6
- "unified",
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/index.d.ts",
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/index.d.ts"
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
  }