@link-assistant/web-capture 1.7.24 → 1.7.25

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @link-assistant/web-capture
2
2
 
3
+ ## 1.7.25
4
+
5
+ ### Patch Changes
6
+
7
+ - 024cb45: Fix `extractAndSaveImages` / `extractBase64ToBuffers` silently dropping base64 images when the markdown image is followed by a title attribute (e.g. `![](data:image/png;base64,... "")`). The base64 payload regex used `[^)]+`, which greedily included the trailing ` ""` and made `Buffer.from()` produce a decoded buffer that no longer matched the original image. The pattern now restricts the payload to base64 alphabet characters and matches the optional trailing markdown title separately so the title cannot leak into the payload.
8
+
3
9
  ## 1.7.24
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@link-assistant/web-capture",
3
- "version": "1.7.24",
3
+ "version": "1.7.25",
4
4
  "description": "CLI and microservice to render web pages as HTML, Markdown, or PNG",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -2,8 +2,11 @@ import { createHash } from 'crypto';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
 
5
+ // Capture groups: alt text, mime subtype, base64 payload. A trailing
6
+ // markdown title attribute (e.g. `![](src "")`) is matched but discarded so
7
+ // the empty title cannot leak into the base64 payload.
5
8
  const BASE64_IMAGE_REGEX =
6
- /!\[([^\]]*)\]\(data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,([^)]+)\)/gi;
9
+ /!\[([^\]]*)\]\(data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,([A-Za-z0-9+/=]+)(?:\s+"[^"]*")?\)/gi;
7
10
 
8
11
  /**
9
12
  * @param {string} markdown - Markdown content with data URI images
@@ -130,6 +130,26 @@ describe('extract-images module', () => {
130
130
  );
131
131
  });
132
132
 
133
+ it('extracts a base64 image even when followed by an empty markdown title', () => {
134
+ // Google Docs HTML exports embed `<img title="" alt="" src="...">`, and
135
+ // the html2md pipeline can render that as `![](src "")`. The base64
136
+ // extractor must still pull the image out cleanly so the rendered
137
+ // markdown does not carry multi-megabyte data URIs.
138
+ const md = `Hello.\n\n![](data:image/png;base64,${TINY_PNG} "")\n\nEnd.\n`;
139
+ const result = extractAndSaveImages(md, tmpDir);
140
+ expect(result.extracted).toBe(1);
141
+ expect(result.markdown).toMatch(/images\/image-[a-f0-9]+\.png/);
142
+ expect(result.markdown).not.toContain('data:image');
143
+ });
144
+
145
+ it('extracts a base64 image with a non-empty markdown title', () => {
146
+ const md = `Hello.\n\n![alt](data:image/png;base64,${TINY_PNG} "caption")\n\nEnd.\n`;
147
+ const result = extractAndSaveImages(md, tmpDir);
148
+ expect(result.extracted).toBe(1);
149
+ expect(result.markdown).toMatch(/images\/image-[a-f0-9]+\.png/);
150
+ expect(result.markdown).not.toContain('data:image');
151
+ });
152
+
133
153
  it('handles SVG data URIs', () => {
134
154
  const svgContent =
135
155
  '<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><rect fill="red" width="1" height="1"/></svg>';