@onozaty/growi-uploader 1.2.0 → 1.3.0

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
@@ -1,5 +1,7 @@
1
1
  # growi-uploader
2
2
 
3
+ [![Test](https://github.com/onozaty/growi-uploader/actions/workflows/test.yaml/badge.svg)](https://github.com/onozaty/growi-uploader/actions/workflows/test.yaml)
4
+ [![codecov](https://codecov.io/gh/onozaty/growi-uploader/graph/badge.svg?token=X0YN1OP5PB)](https://codecov.io/gh/onozaty/growi-uploader)
3
5
  [![npm version](https://badge.fury.io/js/@onozaty%2Fgrowi-uploader.svg)](https://www.npmjs.com/package/@onozaty/growi-uploader)
4
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
7
 
@@ -178,10 +180,22 @@ images/
178
180
  All referenced files (`logo.png`, `screenshot.png`, and `banner.png`) will be uploaded as attachments to the `/guide` page, even though they don't follow the `_attachment_` naming convention.
179
181
 
180
182
  **Path resolution:**
183
+ - Markdown escape sequences are unescaped (`\(` → `(`)
184
+ - URL encoding (percent-encoding) is decoded (`%20` → space, `%E7%94%BB%E5%83%8F` → `画像`)
181
185
  - Relative paths (`./`, `../`, or no prefix): Resolved from the Markdown file's directory
182
186
  - Absolute paths (starting with `/`): Resolved from the source directory root
183
187
  - Example: `/assets/banner.png` → `<source-dir>/assets/banner.png`
184
188
 
189
+ **Supported link formats:**
190
+ ```markdown
191
+ ![Logo](./images/logo.png) # Standard relative path
192
+ ![Logo](images/logo.png) # Relative path without ./
193
+ ![Image](./images/%E7%94%BB%E5%83%8F.png) # URL-encoded Japanese filename
194
+ [File](./docs/my%20file.pdf) # URL-encoded space
195
+ [File](<./path/file (1).png>) # Special chars with angle brackets
196
+ ![Image](./path/file\\(1\\).png) # Special chars with escaping
197
+ ```
198
+
185
199
  **Excluded from detection:**
186
200
  - `.md` files (treated as page links)
187
201
  - External URLs (`http://`, `https://`)
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import { lookup } from "mime-types";
8
8
  import { glob } from "glob";
9
9
 
10
10
  //#region package.json
11
- var version = "1.2.0";
11
+ var version = "1.3.0";
12
12
 
13
13
  //#endregion
14
14
  //#region src/config.ts
@@ -247,9 +247,15 @@ const extractLinkedAttachments = (content, markdownFilePath, sourceDir) => {
247
247
  if (linkPath.startsWith("http://") || linkPath.startsWith("https://")) continue;
248
248
  if (linkPath.endsWith(".md")) continue;
249
249
  const unescapedPath = linkPath.replace(/\\([\\`*_{}[\]()#+\-.!])/g, "$1");
250
+ let decodedPath;
251
+ try {
252
+ decodedPath = decodeURIComponent(unescapedPath);
253
+ } catch {
254
+ decodedPath = unescapedPath;
255
+ }
250
256
  let absolutePath;
251
- if (linkPath.startsWith("/")) absolutePath = resolve(sourceDir, unescapedPath.slice(1));
252
- else absolutePath = resolve(dirname(join(sourceDir, markdownFilePath)), unescapedPath);
257
+ if (linkPath.startsWith("/")) absolutePath = resolve(sourceDir, decodedPath.slice(1));
258
+ else absolutePath = resolve(dirname(join(sourceDir, markdownFilePath)), decodedPath);
253
259
  if (!existsSync(absolutePath)) continue;
254
260
  const normalizedPath = relative(sourceDir, absolutePath).replace(/\\/g, "/");
255
261
  attachments.push({
@@ -343,13 +349,13 @@ const replaceAttachmentLinks = (markdown, attachments, pageName) => {
343
349
  const escapedFileName = escapeRegex(`${pageName}_attachment_${attachment.fileName}`);
344
350
  patterns.push(escapedFileName, `\\./${escapedFileName}`);
345
351
  }
346
- if (attachment.detectionPattern === "link" && attachment.originalLinkPaths) for (const linkPath of attachment.originalLinkPaths) {
352
+ if (attachment.originalLinkPaths) for (const linkPath of attachment.originalLinkPaths) {
347
353
  const escapedPath = escapeRegex(linkPath);
348
354
  patterns.push(escapedPath);
349
355
  if (linkPath.startsWith("./")) {
350
356
  const escapedWithoutDot = escapeRegex(linkPath.substring(2));
351
357
  patterns.push(escapedWithoutDot);
352
- } else if (!linkPath.startsWith("../")) patterns.push(`\\./${escapedPath}`);
358
+ } else if (!linkPath.startsWith("../") && !linkPath.startsWith("<")) patterns.push(`\\./${escapedPath}`);
353
359
  }
354
360
  for (const pattern of patterns) {
355
361
  const imgRegex = new RegExp(`!\\[([^\\]]*)\\]\\(${pattern}\\)`, "g");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onozaty/growi-uploader",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A content uploader for GROWI",
5
5
  "type": "module",
6
6
  "bin": {