Skip to content

Commit 66d286b

Browse files
committed
Update README.md
1 parent 13bda88 commit 66d286b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ const processor = unified()
9999
.use(docx, { plugins: [imagePlugin()] });
100100
```
101101

102+
When we embed `svg` to docx, it also requires `png` image for compatibility reason. On browser, this plugin generate it automatically. On other enviroment like Node.js, please implement `fallbackSvg` prop.
103+
104+
```javascript
105+
import sharp from "sharp";
106+
107+
imagePlugin({
108+
fallbackSvg: async ({ buffer }) => {
109+
const png = await sharp(buffer).png().toBuffer();
110+
return png.buffer;
111+
},
112+
});
113+
```
114+
102115
### Code
103116

104117
Syntax highlighting with [shiki](https://github.com/shikijs/shiki).

src/plugins/image/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type SvgToPngFn = (options: {
7979
buffer: ArrayBuffer;
8080
width: number;
8181
height: number;
82-
}) => Promise<ArrayBuffer>;
82+
}) => Promise<ArrayBufferLike>;
8383

8484
const loadWithFetch: LoadFn = async (url) => {
8585
const res = await fetch(url);
@@ -182,7 +182,7 @@ export const imagePlugin = ({
182182
width,
183183
height,
184184
data,
185-
fallback: fallback,
185+
fallback: fallback as ArrayBuffer,
186186
});
187187
} catch (e) {
188188
warnOnce(`Failed to create fallback image: ${url} ${e}`);

0 commit comments

Comments
 (0)