{"_id":"@1-/md","_rev":"6-291e10e03cc0415e551e026be2eb7c80","name":"@1-/md","dist-tags":{"latest":"0.1.5"},"versions":{"0.1.0":{"name":"@1-/md","version":"0.1.0","keywords":["code-block","extractor","markdown","parser"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/md@0.1.0","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/md","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"3d90a1f067bc3ac90bc20d604083aba9ff875e3b","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.0.tgz","fileCount":5,"integrity":"sha512-dBspiJAHh1QK543vLopd7YDhbVRmqhyiw0kCb4Yr9Wp7YGROJ3nybUgucSXUfZM/QZn69s47yFNF5F860R7waw==","signatures":[{"sig":"MEYCIQCLKPnXJDVgMWnGGP72b8lKyu+rXI0dN3UoDUX7QS5RTwIhAPsn9DpWcPdp4luW7UXYT04GaBy/bbu/JeCtfSUsDkwf","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6512},"type":"module","exports":{"./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.13.0","description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/md_0.1.0_1780974474532_0.8326385557520004","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@1-/md","version":"0.1.1","keywords":["code-block","extractor","markdown","parser"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/md@0.1.1","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/md","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"b97e9e88c32411d5a60f29e6fcdbb191bd481a55","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.1.tgz","fileCount":5,"integrity":"sha512-mti8itfw7r0H2v+PFquZgmTODeBZeSRiZzieg/gTxhmRrnQtS28aiFERlYCXQ6ifJ3VtU5bNm/nqeYS4dHLmig==","signatures":[{"sig":"MEYCIQC7V8BQ/aj1RhdVyf3zVVweJYQkUTcKP5DkLQDhBNBr8wIhAP66hxG+97OgNvfvlhlgh0abcCALPESgFsLTHdP+ARhb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6666},"type":"module","exports":{"./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.13.0","description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/md_0.1.1_1780980905586_0.9878794741751045","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@1-/md","version":"0.1.2","keywords":["code-block","extractor","markdown","parser"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/md@0.1.2","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/md","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"87e4b10541a5ec8a737807fedf9a4e29eb13f8ae","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.2.tgz","fileCount":4,"integrity":"sha512-0QPIKBNb20p5Ul1iIBESXuFU2NGekJHife0zDyfbkI2R09+HHIA58GjaoZQ6ykFEXemt9bu3rAIKqfg5UcH6Mg==","signatures":[{"sig":"MEUCIQD81bt6op7gCsfWLZ/YfrH6T/h7vVRCwyKiW132RXETpwIgFPQz5f4lA0vbdNKRrofSXgVgbJho0Uqco6NhfHMLSuE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7391},"type":"module","exports":{"./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.13.0","description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/md_0.1.2_1780981251321_0.049006253748574924","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@1-/md","version":"0.1.3","keywords":["code-block","extractor","markdown","parser"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/md@0.1.3","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/md","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"9bc8e0666b90598957ce2f423331f67780ebf10e","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.3.tgz","fileCount":4,"integrity":"sha512-9nPq+X34oho7PAoQvHYDH8RqqcgaxyzoB9EcwrxEAZitQB9Whr8IYX4XdHtGmHq0N5VCnzMJO0bikVqqbjTx2g==","signatures":[{"sig":"MEYCIQDMIywDywFgU5B5LOzWG9tMTxhZDjhQxxfhAKdmolCsCAIhAJZIIFTxpTKzbcnCG083fYkrX9F0iGl3cer51Kbxf/BE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7508},"type":"module","exports":{"./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.13.0","description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/md_0.1.3_1781061279807_0.7274407710411128","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@1-/md","version":"0.1.4","keywords":["code-block","extractor","markdown","parser"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/md@0.1.4","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/md","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"f5e8675ef39433dbf850343b56ef53356081747e","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.4.tgz","fileCount":4,"integrity":"sha512-A13w1hk9EKTH2vTU4CYN4PyFZNkH5w+d+Ai9VOtqQq4ZvmbV9cwu9LDHaP+HnqyZeAs8khiUOAMKIjoENjsHBA==","signatures":[{"sig":"MEYCIQCYmU6CbLs+CO8FAtAhVMqzuTICCOFRd1KcsNt7FswjpQIhAKGhEMoZI5T9mSLxR4bZm+JdeqQgc+/oazLihFVctZiU","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8234},"type":"module","exports":{"./*":"./*"},"_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":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/md_0.1.4_1781228201932_0.7056369120267385","host":"s3://npm-registry-packages-npm-production"}},"0.1.5":{"name":"@1-/md","version":"0.1.5","description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","keywords":["code-block","extractor","markdown","parser"],"homepage":"https://github.com/webc-site/npm/tree/main/md","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"type":"module","exports":{"./*":"./*"},"_id":"@1-/md@0.1.5","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-9IMYOrJ9qCKRUTj1QkeF8hRR+FlcLcN5rBJVa585fLWOaFpEQ1u2leEKIgmG4S6M0mIYcNXrFsQSsZoxrVPO/Q==","shasum":"6cc5e8b5ee6aa89ba0f4dd329c5beee64083fb1a","tarball":"https://registry.npmjs.org/@1-/md/-/md-0.1.5.tgz","fileCount":4,"unpackedSize":8231,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDnOTvFQiDIQ9SUJOj6N4xEgimrbnDaP3C6slTSy4gZ0gIgXdwd+NyW2+1kYSWfZO3cN3PTaSESINAHeWbcsB3uQDo="}]},"_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/md_0.1.5_1781255409998_0.5158793355401892"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-09T03:07:54.353Z","modified":"2026-06-12T09:10:10.345Z","0.1.0":"2026-06-09T03:07:54.704Z","0.1.1":"2026-06-09T04:55:05.739Z","0.1.2":"2026-06-09T05:00:51.438Z","0.1.3":"2026-06-10T03:14:39.933Z","0.1.4":"2026-06-12T01:36:42.062Z","0.1.5":"2026-06-12T09:10:10.147Z"},"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/md","keywords":["code-block","extractor","markdown","parser"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"description":"Extract code blocks and languages from Markdown / 解析 Markdown 提取代码块位置与语言类型","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @1-/md : Extract code block positions and languages from Markdown\n\n- [@1-/md : Extract code block positions and languages from Markdown](#1-md-extract-code-block-positions-and-languages-from-markdown)\n  - [1. Features](#1-features)\n  - [2. Usage](#2-usage)\n  - [3. Design](#3-design)\n  - [4. Tech Stack](#4-tech-stack)\n  - [5. Code Structure](#5-code-structure)\n  - [6. History](#6-history)\n  - [About](#about)\n\n## 1. Features\n\nExtract code block locations and language identifiers from Markdown text.\n\n- Normalize cross-platform line endings (\\r\\n, \\r) to standard \\n\n- Support fenced code blocks with any number of consecutive backticks (≥3)\n- Accurately extract language identifiers, including empty strings for language-agnostic blocks\n- Record start and end line numbers (1-based indexing) for each code block\n- Automatically close unclosed code blocks at document end\n\n## 2. Usage\n\n```javascript\nimport li from \"@1-/md/li.js\";\nimport code from \"@1-/md/code.js\";\n\nconst markdownContent = `# Title\n\n\\`\\`\\`javascript\nconst val = 1;\n\\`\\`\\``;\n\n// Split Markdown text into normalized line array\nconst lines = li(markdownContent);\n\n// Extract all code block information\nconst blocks = code(lines);\n\nconsole.log(blocks);\n// Output format: [ [ Language, Start Line, End Line ] ]\n// Example output: [ [ 'javascript', 3, 5 ] ]\n```\n\n## 3. Design\n\nThe system consists of two independent modules: line normalization (`li.js`) and code block extraction (`code.js`).\n\n`li.js` normalizes cross-platform line endings and splits text into line arrays while trimming trailing whitespace from each line.\n\n`code.js` uses a state machine to iterate through the line array:\n- Initial state (outside code block): match lines starting with ≥3 backticks, record backtick count, language, and start line number, transition to inside state\n- Inside code block state: match ending lines with identical backtick count, record end line number and save block information, transition back to outside state\n- Document end: if still inside a code block, use total line count as end line number and save the unclosed block\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@mj/DXK8MLuvsCI7tDHxhUgw.svg)\n\n## 4. Tech Stack\n\n- Runtime: Bun / Node.js\n- Language: JavaScript (ES Modules)\n- Linter: Oxlint\n- Formatter: Oxfmt\n\n## 5. Code Structure\n\n```\n.\n├── src/\n│   ├── code.js          # Code block extraction logic\n│   └── li.js            # Line normalization processing\n└── test/\n    ├── _.test.js        # Unit test\n    └── test.md          # Markdown test cases\n```\n\n## 6. History\n\nIn 2004, John Gruber and Aaron Swartz co-created the Markdown markup language, with early specifications supporting only indented code blocks.\n\nIn 2012, GitHub introduced fenced code blocks in GitHub Flavored Markdown (GFM), using backticks (`) to wrap code with optional language identifiers, significantly improving readability and practicality of technical documentation.\n\nIn 2014, fenced code blocks were standardized in the CommonMark specification, becoming a core feature of modern Markdown implementations across documentation generators, static site builders, and development tools.\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-/md : 解析 Markdown 提取代码块位置与语言类型\n\n- [@1-/md : 解析 Markdown 提取代码块位置与语言类型](#1-md-解析-markdown-提取代码块位置与语言类型)\n  - [1. 功能介绍](#1-功能介绍)\n  - [2. 使用演示](#2-使用演示)\n  - [3. 设计思路](#3-设计思路)\n  - [4. 技术栈](#4-技术栈)\n  - [5. 代码结构](#5-代码结构)\n  - [6. 历史故事](#6-历史故事)\n  - [关于](#关于)\n\n## 1. 功能介绍\n\n提取 Markdown 文本中围栏代码块的位置信息与语言标识。\n\n- 统一处理跨平台换行符（\\r\\n、\\r）为标准 \\n\n- 支持任意数量连续反引号（≥3）定义的围栏代码块\n- 准确提取代码块语言标识，包括无语言标识的空字符串情况\n- 记录每个代码块的起始行号与结束行号（1-based indexing）\n- 自动闭合文档末尾未配对的代码块\n\n## 2. 使用演示\n\n```javascript\nimport li from \"@1-/md/li.js\";\nimport code from \"@1-/md/code.js\";\n\nconst markdownContent = `# Title\n\n\\`\\`\\`javascript\nconst val = 1;\n\\`\\`\\``;\n\n// 将 Markdown 文本拆分为标准化的行数组\nconst lines = li(markdownContent);\n\n// 提取所有代码块信息\nconst blocks = code(lines);\n\nconsole.log(blocks);\n// 输出格式: [ [ 语言类型, 起始行号, 结束行号 ] ]\n// 示例输出: [ [ 'javascript', 3, 5 ] ]\n```\n\n## 3. 设计思路\n\n系统由两个独立模块组成：行标准化模块（`li.js`）和代码块提取模块（`code.js`）。\n\n`li.js` 模块统一处理不同平台的换行符，将文本分割为行数组，并清除每行末尾空白字符。\n\n`code.js` 模块使用状态机遍历行数组：\n- 初始状态（代码块外）：匹配以 ≥3 个反引号开头的行，记录反引号数量、语言类型及起始行号，切换至代码块内状态\n- 代码块内状态：匹配相同数量反引号的结束行，记录结束行号并保存代码块信息，切换回代码块外状态\n- 文档末尾：若仍处于代码块内状态，则以文档总行数作为结束行号，保存未闭合代码块\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@ge/t8KN1E8DWqse-d5KmHRg.svg)\n\n## 4. 技术栈\n\n- 运行时: Bun / Node.js\n- 语言: JavaScript (ES Modules)\n- 代码检查: Oxlint\n- 代码格式化: Oxfmt\n\n## 5. 代码结构\n\n```\n.\n├── src/\n│   ├── code.js          # 代码块提取逻辑\n│   └── li.js            # 行标准化处理\n└── test/\n    ├── _.test.js        # 单元测试\n    └── test.md          # 测试用 Markdown 样例\n```\n\n## 6. 历史故事\n\n2004 年，John Gruber 与 Aaron Swartz 共同创建 Markdown 标记语言，早期规范仅支持缩进方式定义代码块。\n\n2012 年，GitHub 在 GitHub Flavored Markdown (GFM) 中引入围栏代码块语法，使用反引号（`）包裹代码并支持语言标识，大幅提升技术文档可读性与实用性。\n\n2014 年，围栏代码块被纳入 CommonMark 规范，成为现代 Markdown 的标准特性，广泛应用于文档生成、静态网站构建和开发工具中。\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n\n","readmeFilename":"README.md"}