remark-inline-svg-flex 0.2.3 → 0.3.4

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/README.md CHANGED
@@ -61,16 +61,21 @@ This is a test markdown document.
61
61
  ![some svg](some.svg)
62
62
  ```
63
63
 
64
- And our module `example.js` looks as follows:
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.
65
67
 
66
68
  ```js
67
69
  import { remark } from 'remark';
68
70
  import { readFile } from 'node:fs/promises';
69
- import { inlineSvg } from 'remark-inline-svg-flex';
71
+ import { remarkInlineSvg } from 'remark-inline-svg-flex';
70
72
 
71
73
  const markdown = await readFile(_path, { encoding: 'utf8' });
72
74
 
73
- return await remark().use(remarkParse).use(inlineSvg).process(markdown);
75
+ return await remark()
76
+ .use(remarkParse)
77
+ .use(remarkInlineSvg)
78
+ .process({ value: markdown, path: _path });
74
79
  ```
75
80
 
76
81
  Now running `node example.js` yields:
@@ -120,5 +125,5 @@ The SVG's are optimized by default. Disable it by setting it to `false`.
120
125
  ## SVGO configuration
121
126
 
122
127
  ```
123
- { plugins: ['preset-default', 'removeXMLNS', 'removeDimensions'] }
128
+ { plugins: ['preset-default', 'removeXMLNS'] }
124
129
  ```
@@ -10,5 +10,5 @@ import type { Options } from './types';
10
10
  * @param options.wrapper - Optional HTML wrapper for the inline SVG (default: `<figure class="inline-svg"></figure>`)
11
11
  * @param options.svgo - Whether to optimize SVG using SVGO (default: true)
12
12
  */
13
- declare const inlineSvg: Plugin<[Options?], Root, Root>;
14
- export { inlineSvg };
13
+ declare const remarkInlineSvg: Plugin<[Options?], Root, Root>;
14
+ export { remarkInlineSvg };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inlineSvg = void 0;
3
+ exports.remarkInlineSvg = void 0;
4
4
  const node_path_1 = require("node:path");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const unist_util_visit_1 = require("unist-util-visit");
@@ -14,7 +14,7 @@ const svgo_1 = require("svgo");
14
14
  * @param options.wrapper - Optional HTML wrapper for the inline SVG (default: `<figure class="inline-svg"></figure>`)
15
15
  * @param options.svgo - Whether to optimize SVG using SVGO (default: true)
16
16
  */
17
- const inlineSvg = (consumerOptions = {}) => {
17
+ const remarkInlineSvg = (consumerOptions = {}) => {
18
18
  const options = {
19
19
  suffix: consumerOptions.suffix ?? '.svg',
20
20
  assetsDir: consumerOptions.assetsDir,
@@ -39,7 +39,7 @@ const inlineSvg = (consumerOptions = {}) => {
39
39
  });
40
40
  };
41
41
  };
42
- exports.inlineSvg = inlineSvg;
42
+ exports.remarkInlineSvg = remarkInlineSvg;
43
43
  /**
44
44
  * Reads an SVG file and optionally optimizes it with SVGO.
45
45
  */
@@ -61,7 +61,7 @@ function wrap(svgString, htmlWrapper) {
61
61
  * Resolves the final SVG file path based on:
62
62
  * 1) absolute URL → from project root
63
63
  * 2) `assetsDir` → relative to it
64
- * 3) fallback → relative to Markdown file directory
64
+ * 3) fallback → relative to Markdown file directory (if markdown file directory is undefined use absolute URL)
65
65
  */
66
66
  function resolvePath(assetsDir, node, markdownFileDir) {
67
67
  if (node_path_1.default.isAbsolute(node.url)) {
@@ -71,7 +71,7 @@ function resolvePath(assetsDir, node, markdownFileDir) {
71
71
  return node_path_1.default.resolve(process.cwd(), assetsDir, node.url);
72
72
  }
73
73
  else {
74
- return node_path_1.default.resolve(markdownFileDir, node.url);
74
+ return node_path_1.default.resolve(markdownFileDir ?? process.cwd(), node.url);
75
75
  }
76
76
  }
77
77
  /**
@@ -79,6 +79,6 @@ function resolvePath(assetsDir, node, markdownFileDir) {
79
79
  */
80
80
  function optimizeSvg(svgString) {
81
81
  return (0, svgo_1.optimize)(svgString, {
82
- plugins: ['preset-default', 'removeXMLNS', 'removeDimensions'],
82
+ plugins: ['preset-default', 'removeXMLNS'],
83
83
  });
84
84
  }
package/dist/plugin.d.ts CHANGED
@@ -10,5 +10,5 @@ import type { Options } from './types';
10
10
  * @param options.wrapper - Optional HTML wrapper for the inline SVG (default: `<figure class="inline-svg"></figure>`)
11
11
  * @param options.svgo - Whether to optimize SVG using SVGO (default: true)
12
12
  */
13
- declare const inlineSvg: Plugin<[Options?], Root, Root>;
14
- export { inlineSvg };
13
+ declare const remarkInlineSvg: Plugin<[Options?], Root, Root>;
14
+ export { remarkInlineSvg };
package/dist/plugin.js CHANGED
@@ -12,7 +12,7 @@ import { optimize } from 'svgo';
12
12
  * @param options.wrapper - Optional HTML wrapper for the inline SVG (default: `<figure class="inline-svg"></figure>`)
13
13
  * @param options.svgo - Whether to optimize SVG using SVGO (default: true)
14
14
  */
15
- const inlineSvg = (consumerOptions = {}) => {
15
+ const remarkInlineSvg = (consumerOptions = {}) => {
16
16
  const options = {
17
17
  suffix: consumerOptions.suffix ?? '.svg',
18
18
  assetsDir: consumerOptions.assetsDir,
@@ -58,7 +58,7 @@ function wrap(svgString, htmlWrapper) {
58
58
  * Resolves the final SVG file path based on:
59
59
  * 1) absolute URL → from project root
60
60
  * 2) `assetsDir` → relative to it
61
- * 3) fallback → relative to Markdown file directory
61
+ * 3) fallback → relative to Markdown file directory (if markdown file directory is undefined use absolute URL)
62
62
  */
63
63
  function resolvePath(assetsDir, node, markdownFileDir) {
64
64
  if (path.isAbsolute(node.url)) {
@@ -68,7 +68,7 @@ function resolvePath(assetsDir, node, markdownFileDir) {
68
68
  return path.resolve(process.cwd(), assetsDir, node.url);
69
69
  }
70
70
  else {
71
- return path.resolve(markdownFileDir, node.url);
71
+ return path.resolve(markdownFileDir ?? process.cwd(), node.url);
72
72
  }
73
73
  }
74
74
  /**
@@ -76,7 +76,7 @@ function resolvePath(assetsDir, node, markdownFileDir) {
76
76
  */
77
77
  function optimizeSvg(svgString) {
78
78
  return optimize(svgString, {
79
- plugins: ['preset-default', 'removeXMLNS', 'removeDimensions'],
79
+ plugins: ['preset-default', 'removeXMLNS'],
80
80
  });
81
81
  }
82
- export { inlineSvg };
82
+ export { remarkInlineSvg };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-inline-svg-flex",
3
- "version": "0.2.3",
3
+ "version": "0.3.4",
4
4
  "description": "Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution and wrappers.",
5
5
  "keywords": [
6
6
  "unified",
@@ -48,11 +48,11 @@
48
48
  "rimraf": "^6.1.3",
49
49
  "typescript": "^5.9.3",
50
50
  "unified": "^11.0.5",
51
- "vfile": "^6.0.3",
52
51
  "vitest": "^4.1.0"
53
52
  },
54
53
  "dependencies": {
55
54
  "svgo": "^4.0.1",
56
- "unist-util-visit": "^5.1.0"
55
+ "unist-util-visit": "^5.1.0",
56
+ "vfile": "^6.0.3"
57
57
  }
58
58
  }