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.
@@ -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
  [![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,21 +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
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(_path, { encoding: 'utf8' });
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: _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 fill="none" viewBox="0 0 250 250" role="img" aria-hidden="true"><circle cx="125" cy="125" r="100" fill="#BA5B5B"/></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
  ```
@@ -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.7",
4
- "description": "Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution and wrappers.",
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
- "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
  }