{"_id":"@1-/mdimg2cdn","_rev":"3-f7cfb121029b732ee0d27137675d2915","name":"@1-/mdimg2cdn","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@1-/mdimg2cdn","version":"0.1.0","keywords":["markdown","cdn","images","upload","static"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/mdimg2cdn@0.1.0","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/mdimg2cdn","bugs":{"url":"https://github.com/webc-site/npm/issues"},"bin":{"mdimg2cdn":"cli.js"},"dist":{"shasum":"4e570a63e3de0059d5ee8852fadbed1a2242793d","tarball":"https://registry.npmjs.org/@1-/mdimg2cdn/-/mdimg2cdn-0.1.0.tgz","fileCount":5,"integrity":"sha512-wqn4G7grxDzwqwC5m73p1SIlp6kEImbE+7XTgSHnLkYwHq/DWIKEukbCbHStj0LDprMN5mYt+YozC3CRZC+emA==","signatures":[{"sig":"MEUCIQCuBsTLg3Y+ON2p83i13mikwqH2TIBhJ/UJj0NpGkbA1AIgbHxrTc9dd2aKy0Ov2OiuZn1iYnBRE77lHmSAOAbKZQg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10209},"type":"module","exports":{".":"./_.js","./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.16.0","description":"Convert local image references in Markdown documents to CDN URLs. 将 Markdown 文档中的本地图片引用转换为 CDN 链接。","directories":{},"_nodeVersion":"26.2.0","dependencies":{"yargs":"^18.0.0","@1-/md":"^0.1.5","@1-/read":"^0.1.1","@1-/findgit":"^0.1.2","@1-/mdmermaid":"^0.1.5","@1-/github_cdn":"^0.1.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mdimg2cdn_0.1.0_1781258594084_0.8951328671439192","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@1-/mdimg2cdn","version":"0.1.1","keywords":["markdown","cdn","images","upload","static"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/mdimg2cdn@0.1.1","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/mdimg2cdn","bugs":{"url":"https://github.com/webc-site/npm/issues"},"bin":{"mdimg2cdn":"cli.js"},"dist":{"shasum":"26e36ec0a35325c2cd9488665acc2e86ed3f92aa","tarball":"https://registry.npmjs.org/@1-/mdimg2cdn/-/mdimg2cdn-0.1.1.tgz","fileCount":5,"integrity":"sha512-MiuLV9ihm4axm4OIqPgwdFg9OfcmKuRxZsvU1Wx9mqto2i6Lka9fvuvKdG02RbPc5wUD6u7rsb+ybapNzW5qPw==","signatures":[{"sig":"MEUCID8XNdaq0wsYVFAehCdZyrauzxuc3XqzvMDupcTPIs19AiEAtgRXf1JInwnsJOUNryc2qBwiCX+TPfz8cMTtS31QRfM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15878},"type":"module","exports":{".":"./_.js","./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.16.0","description":"Convert local image references in Markdown documents to CDN URLs. 将 Markdown 文档中的本地图片引用转换为 CDN 链接。","directories":{},"_nodeVersion":"26.2.0","dependencies":{"yargs":"^18.0.0","@1-/md":"^0.1.5","@1-/read":"^0.1.1","@1-/findgit":"^0.1.2","@1-/mdmermaid":"^0.1.5","@1-/github_cdn":"^0.1.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mdimg2cdn_0.1.1_1781260401573_0.3367095826322617","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@1-/mdimg2cdn","version":"0.1.2","description":"Convert local image references in Markdown documents to CDN URLs. 将 Markdown 文档中的本地图片引用转换为 CDN 链接。","keywords":["cdn","images","markdown","static","upload"],"homepage":"https://github.com/webc-site/npm/tree/main/mdimg2cdn","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"bin":{"mdimg2cdn":"cli.js"},"type":"module","exports":{".":"./_.js","./*":"./*"},"dependencies":{"@1-/findgit":"^0.1.2","@1-/github_cdn":"^0.1.1","@1-/md":"^0.1.5","@1-/mdmermaid":"^0.1.5","@1-/read":"^0.1.1","yargs":"^18.0.0"},"_id":"@1-/mdimg2cdn@0.1.2","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-694qfaToYQTEaDfQkBvYE6I+kPchtKFxYwOyCrUTmAKAHVov5xss6fdxFHtRz7oPI5DmoSAZ2TW03mfajPo23Q==","shasum":"c7a8f3988f3d74897a5d9abec3f533ec3d00806e","tarball":"https://registry.npmjs.org/@1-/mdimg2cdn/-/mdimg2cdn-0.1.2.tgz","fileCount":5,"unpackedSize":17858,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHOBtLSvSAt6m5g6eUczNJi4ldapY3e5X69JyVmwJtM8AiEAhJ68/nWhNmLGRzNYgLghINXhMjyvEkdQFRB+4J6bySM="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mdimg2cdn_0.1.2_1783693461908_0.7357370839344164"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-12T10:03:13.887Z","modified":"2026-07-10T14:24:22.220Z","0.1.0":"2026-06-12T10:03:14.309Z","0.1.1":"2026-06-12T10:33:21.724Z","0.1.2":"2026-07-10T14:24:22.074Z"},"bugs":{"url":"https://github.com/webc-site/npm/issues"},"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","homepage":"https://github.com/webc-site/npm/tree/main/mdimg2cdn","keywords":["cdn","images","markdown","static","upload"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"description":"Convert local image references in Markdown documents to CDN URLs. 将 Markdown 文档中的本地图片引用转换为 CDN 链接。","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @1-/mdimg2cdn : Convert local Markdown images to CDN URLs\n\n- [@1-/mdimg2cdn : Convert local Markdown images to CDN URLs](#1-mdimg2cdn-convert-local-markdown-images-to-cdn-urls)\n  - [Functionality](#functionality)\n  - [Usage Demonstration](#usage-demonstration)\n  - [Design Rationale](#design-rationale)\n  - [Technology Stack](#technology-stack)\n  - [Code Structure](#code-structure)\n  - [Historical Context](#historical-context)\n  - [About](#about)\n\n## Functionality\n\n@1-/mdimg2cdn processes Markdown documents to identify local image references and replaces them with CDN-hosted URLs. It handles both Markdown syntax (`![alt](path/to/image.png)`) and HTML `<img>` tags while intelligently skipping code blocks and inline code to avoid unintended replacements.\n\nThe tool integrates Mermaid diagram rendering by uploading generated SVG images to CDN storage, enabling consistent visual presentation across different environments.\n\n## Usage Demonstration\n\nInstall as a CLI tool:\n\n```bash\nnpm install -g @1-/mdimg2cdn\n```\n\nProcess a Markdown file and output to stdout:\n\n```bash\nmdimg2cdn README.md\n```\n\nWrite changes back to the original file:\n\n```bash\nmdimg2cdn README.md --write\n```\n\nAs a library in JavaScript:\n\n```javascript\nimport mdimg2cdn from \"@1-/mdimg2cdn\";\n\nconst processedMd = await mdimg2cdn(\n  markdownContent,\n  async (buffer, ext) => {\n    // Your CDN upload logic here\n    return \"https://cdn.example.com/image.png\";\n  },\n  \"/path/to/base/directory\",\n);\n```\n\n## Design Rationale\n\nThe architecture follows a pipeline pattern with clear separation of concerns:\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@Fo/MbaHCHKO898-nbR0O-Xw.svg)\n\nKey design decisions:\n\n- State machine parsing for robust URL extraction from both Markdown and HTML syntax\n- Code block and inline code detection to prevent false positives in code examples\n- Mermaid integration for dynamic diagram rendering\n- Asynchronous processing to handle file I/O and network operations efficiently\n\n## Technology Stack\n\n- Runtime: bun (ES modules)\n- Core dependencies: `@1-/md/li.js`, `@1-/md/code.js`, `@1-/mdmermaid`, `@1-/read`, `@1-/findgit`, `@1-/github_cdn`\n- CLI framework: yargs\n\n## Code Structure\n\n```\nsrc/\n├── _.js          # Main transformation function, orchestrates parsing, upload, and replacement\n├── cli.js        # Command-line interface, handles arguments, path resolution, and config loading\n└── parse.js      # State machines for extracting image URLs from Markdown and HTML\n```\n\nThe core module (`_.js`) implements the main transformation algorithm, `cli.js` manages the CLI entry point and GitHub CDN configuration, and `parse.js` contains specialized state machines for precise URL extraction.\n\n## Historical Context\n\nThe concept of content delivery networks emerged in the late 1990s. Akamai Technologies, founded in 1998, pioneered the CDN approach by distributing content across geographically dispersed edge servers to address web performance bottlenecks caused by geographic distance between users and origin servers. Akamai's foundational technology stemmed from research by MIT professor Tom Leighton and his team, whose algorithms optimized internet content routing and caching. Today's modern Markdown tooling like @1-/mdimg2cdn builds upon this foundational infrastructure, enabling developers to leverage CDN benefits without manual image management overhead.\n\n## About\n\nThis library is developed by [WebC.site](https://webc.site).\n\n[WebC.site](https://webc.site): A new paradigm of web development for AI\n\n\n---\n\n<a id=\"zh\"></a>\n# @1-/mdimg2cdn : 将本地 Markdown 图片转换为 CDN 链接\n\n- [@1-/mdimg2cdn : 将本地 Markdown 图片转换为 CDN 链接](#1-mdimg2cdn-将本地-markdown-图片转换为-cdn-链接)\n  - [功能介绍](#功能介绍)\n  - [使用演示](#使用演示)\n  - [设计思路](#设计思路)\n  - [技术栈](#技术栈)\n  - [代码结构](#代码结构)\n  - [历史故事](#历史故事)\n  - [关于](#关于)\n\n## 功能介绍\n\n@1-/mdimg2cdn 处理 Markdown 文档，识别本地图片引用并替换为 CDN 托管的 URL。支持 Markdown 语法（`![alt](path/to/image.png)`）和 HTML `<img>` 标签，同时智能跳过代码块与行内代码以避免错误替换。\n\n工具集成 Mermaid 图表渲染，将生成的 SVG 图片上传至 CDN，确保在不同环境中呈现一致的视觉效果。\n\n## 使用演示\n\n作为 CLI 工具安装：\n\n```bash\nnpm install -g @1-/mdimg2cdn\n```\n\n处理 Markdown 文件并输出到标准输出：\n\n```bash\nmdimg2cdn README.md\n```\n\n将更改写回原始文件：\n\n```bash\nmdimg2cdn README.md --write\n```\n\n在 JavaScript 中作为库使用：\n\n```javascript\nimport mdimg2cdn from \"@1-/mdimg2cdn\";\n\nconst processedMd = await mdimg2cdn(\n  markdownContent,\n  async (buffer, ext) => {\n    // 自定义 CDN 上传逻辑\n    return \"https://cdn.example.com/image.png\";\n  },\n  \"/path/to/base/directory\",\n);\n```\n\n## 设计思路\n\n架构采用管道模式，关注点分离清晰：\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@dP/7iuF3DeQt-O44xs3siNw.svg)\n\n关键设计考量：\n\n- 状态机解析，确保从 Markdown 和 HTML 语法中稳健提取图片 URL\n- 代码块与行内代码检测，防止在代码示例中产生误匹配\n- Mermaid 集成，支持动态图表渲染\n- 异步处理，高效管理文件 I/O 和网络操作\n\n## 技术栈\n\n- 运行时：bun（ES 模块）\n- 核心依赖：`@1-/md/li.js`, `@1-/md/code.js`, `@1-/mdmermaid`, `@1-/read`, `@1-/findgit`, `@1-/github_cdn`\n- CLI 框架：yargs\n\n## 代码结构\n\n```\nsrc/\n├── _.js          # 主转换函数，协调解析、上传与替换流程\n├── cli.js        # 命令行接口，处理参数、路径解析与配置加载\n└── parse.js      # Markdown 与 HTML 图片 URL 解析状态机\n```\n\n核心模块（`_.js`）实现主转换逻辑，`cli.js` 负责 CLI 入口与 GitHub CDN 配置加载，`parse.js` 提供专用状态机以精确提取图片 URL。\n\n## 历史故事\n\n内容分发网络（CDN）概念诞生于 20 世纪 90 年代末。1998 年成立的 Akamai Technologies 开创性地采用分布式边缘服务器架构部署 CDN，旨在解决因用户与源服务器地理距离导致的网页性能瓶颈。Akamai 的技术基础源于麻省理工学院教授 Tom Leighton 及其团队的研究，其算法有效优化了互联网内容的路由与缓存策略。如今 @1-/mdimg2cdn 等现代 Markdown 工具构建于这一基础设施之上，使开发者无需手动管理图片即可享受 CDN 带来的性能优势。\n\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n\n","readmeFilename":"README.md"}