Skip to content
This repository was archived by the owner on Mar 30, 2025. It is now read-only.

Commit b6189d3

Browse files
committed
Update breaking dependencies
- Update to `puppeteer-core@19`. - Update to `svgo@3`. - Remove `@types/svgo`, since `svgo` now ship their own type definitions. - Remove `@types/mermaid`, since `mermaid` now ship their own type definitions. - Use default SVGO options. - Instead of `null`, use `false` to disable SVG minification.
1 parent 529e44b commit b6189d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+569
-2783
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/*-snapshots/*
22
coverage/
33
dist/
4+
test-results/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ information, see the Puppeteer
2424
This plugin takes all code blocks marked as `mermaid` and renders them as an inline SVG.
2525

2626
```js
27-
import { readFile } from 'fs/promises';
27+
import { readFile } from 'node:fs/promises';
2828

2929
import { remark } from 'remark';
3030
import remarkMermaid from 'remark-mermaidjs';

index.ts

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,20 @@
1-
import { createRequire } from 'module';
1+
import { createRequire } from 'node:module';
22

33
import { fromParse5 } from 'hast-util-from-parse5';
44
import { type Code, type Parent, type Root } from 'mdast';
5-
import { type Mermaid } from 'mermaid';
5+
import { type MermaidConfig } from 'mermaid';
66
import { parseFragment } from 'parse5';
77
import puppeteer, { type Browser, type Page, type PuppeteerLaunchOptions } from 'puppeteer-core';
8-
import { optimize, type OptimizedSvg, type OptimizeOptions } from 'svgo';
8+
import { type Config, optimize } from 'svgo';
99
import { type Plugin } from 'unified';
1010
import { visit } from 'unist-util-visit';
1111

1212
const mermaidScript = {
1313
path: createRequire(import.meta.url).resolve('mermaid/dist/mermaid.min.js'),
1414
};
1515

16-
declare const mermaid: Mermaid;
17-
18-
export const defaultSVGOOptions: OptimizeOptions = {
19-
js2svg: {
20-
indent: 2,
21-
pretty: true,
22-
},
23-
multipass: false,
24-
plugins: [
25-
{ name: 'addAttributesToSVGElement', active: false },
26-
{ name: 'addClassesToSVGElement', active: false },
27-
{ name: 'cleanupAttrs', active: true },
28-
{ name: 'cleanupEnableBackground', active: false },
29-
{ name: 'cleanupListOfValues', active: false },
30-
{ name: 'cleanupNumericValues', active: true },
31-
{ name: 'convertColors', active: true },
32-
{ name: 'convertEllipseToCircle', active: true },
33-
{ name: 'convertPathData', active: true },
34-
{ name: 'convertShapeToPath', active: false },
35-
{ name: 'convertTransform', active: true },
36-
{ name: 'minifyStyles', active: true },
37-
{ name: 'inlineStyles', active: true, params: { onlyMatchedOnce: false } },
38-
{ name: 'convertStyleToAttrs', active: true },
39-
{ name: 'mergePaths', active: true },
40-
{ name: 'moveElemsAttrsToGroup', active: false },
41-
{ name: 'moveGroupAttrsToElems', active: false },
42-
{ name: 'prefixIds', active: false },
43-
{ name: 'removeAttributesBySelector', active: false },
44-
{ name: 'removeComments', active: true },
45-
{ name: 'removeDesc', active: true },
46-
{ name: 'removeDimensions', active: false },
47-
{ name: 'removeDoctype', active: true },
48-
{ name: 'removeEditorsNSData', active: true },
49-
{ name: 'removeElementsByAttr', active: false },
50-
{ name: 'removeEmptyAttrs', active: false },
51-
{ name: 'removeEmptyContainers', active: true },
52-
{ name: 'removeEmptyText', active: true },
53-
{ name: 'removeHiddenElems', active: true },
54-
{ name: 'removeMetadata', active: true },
55-
{ name: 'removeNonInheritableGroupAttrs', active: true },
56-
{ name: 'removeOffCanvasPaths', active: true },
57-
{ name: 'removeRasterImages', active: true },
58-
{ name: 'removeScriptElement', active: true },
59-
{ name: 'removeStyleElement', active: true },
60-
{ name: 'removeTitle', active: true },
61-
{ name: 'removeUnknownsAndDefaults', active: true },
62-
{ name: 'removeUnusedNS', active: true },
63-
{ name: 'removeUselessDefs', active: true },
64-
{ name: 'removeUselessStrokeAndFill', active: true, params: { removeNone: true } },
65-
{ name: 'removeViewBox', active: true },
66-
{ name: 'removeXMLNS', active: true },
67-
{ name: 'removeXMLProcInst', active: true },
68-
{ name: 'reusePaths', active: true },
69-
{ name: 'removeAttrs', active: true, params: { attrs: ['class'] } },
70-
{ name: 'cleanupIDs', active: true },
71-
{ name: 'sortAttrs', active: true },
72-
{ name: 'sortDefsChildren', active: true },
73-
{ name: 'collapseGroups', active: true },
74-
],
75-
};
16+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
17+
declare const mermaid: typeof import('mermaid').default;
7618

7719
export interface RemarkMermaidOptions {
7820
/**
@@ -85,21 +27,21 @@ export interface RemarkMermaidOptions {
8527
/**
8628
* SVGO options used to minify the SVO output.
8729
*
88-
* Set to `null` explicitly to disable this.
30+
* Set to `false` explicitly to disable this.
8931
*
9032
* **Note**: This options is only supported in Node.js. In the browser this option is unused.
9133
*
9234
* @default defaultSVGOOptions
9335
*/
94-
svgo?: OptimizeOptions | null;
36+
svgo?: Config | false;
9537

9638
/**
9739
* The mermaid options to use.
9840
*
9941
* **Note**: This options is only supported in Node.js. In the browser this option is unused. If
10042
* you use this in a browser, call `mermaid.initialize()` manually.
10143
*/
102-
mermaidOptions?: Parameters<typeof mermaid['initialize']>[0];
44+
mermaidOptions?: MermaidConfig;
10345
}
10446

10547
/**
@@ -110,7 +52,7 @@ const remarkMermaid: Plugin<[RemarkMermaidOptions?], Root> = (options) => {
11052
throw new Error('The option `launchOptions.executablePath` is required when using Node.js');
11153
}
11254

113-
const { launchOptions, mermaidOptions, svgo = defaultSVGOOptions } = options;
55+
const { launchOptions, mermaidOptions, svgo } = options;
11456

11557
let browserPromise: Promise<Browser> | undefined;
11658
let count = 0;
@@ -166,8 +108,8 @@ const remarkMermaid: Plugin<[RemarkMermaidOptions?], Root> = (options) => {
166108

167109
for (const [i, [, index, parent]] of instances.entries()) {
168110
let value = results[i];
169-
if (svgo) {
170-
value = (optimize(value, svgo) as OptimizedSvg).data;
111+
if (svgo !== false) {
112+
value = optimize(value, svgo).data;
171113
}
172114
parent.children.splice(index, 1, {
173115
type: 'paragraph',

0 commit comments

Comments
 (0)