{"id":31757302,"url":"https://github.com/sec-ant/lezer-commonmark","last_synced_at":"2025-10-09T19:55:44.559Z","repository":{"id":312587431,"uuid":"1047983933","full_name":"Sec-ant/lezer-commonmark","owner":"Sec-ant","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-07T08:07:14.000Z","size":206,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T10:10:40.281Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sec-ant.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-31T17:01:06.000Z","updated_at":"2025-09-01T09:51:17.000Z","dependencies_parsed_at":"2025-08-31T19:07:31.473Z","dependency_job_id":"6ad51bdf-3008-4d35-8ef0-3cae85c77b21","html_url":"https://github.com/Sec-ant/lezer-commonmark","commit_stats":null,"previous_names":["sec-ant/lezer-commonmark"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Sec-ant/lezer-commonmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sec-ant%2Flezer-commonmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sec-ant%2Flezer-commonmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sec-ant%2Flezer-commonmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sec-ant%2Flezer-commonmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sec-ant","download_url":"https://codeload.github.com/Sec-ant/lezer-commonmark/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sec-ant%2Flezer-commonmark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001946,"owners_count":26083244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-09T19:55:41.043Z","updated_at":"2025-10-09T19:55:44.553Z","avatar_url":"https://github.com/Sec-ant.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lezer-commonmark\n\n[![npm](https://img.shields.io/npm/v/lezer-commonmark)](https://www.npmjs.com/package/lezer-commonmark) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/lezer-commonmark)](https://www.npmjs.com/package/lezer-commonmark) [![license](https://img.shields.io/npm/l/lezer-commonmark)](./LICENSE)\n\n一个基于 [Lezer](https://lezer.codemirror.net/) + micromark external tokenizer 的 **CommonMark 解析器**（进行中 WIP）。目标：\n\n1. 语义与 micromark 完全一致（块级 + 行内）\n2. 通过官方 CommonMark 测试套件\n3. 支持增量解析与 CodeMirror 生态集成\n4. 提供语法高亮与类型安全的树遍历 API\n\n## Install\n\n```bash\npnpm add lezer-commonmark\n```\n\n## Development\n\n这个项目使用 `unplugin-lezer/vite` 来处理语法文件。开发时的常用命令：\n\n```bash\ngit clone https://github.com/Sec-ant/lezer-commonmark\ncd lezer-commonmark\npnpm install\n\n# 开发时生成 grammar 文件（运行测试或脚本前需要）\nnpm run dev:grammar\n\n# 运行测试\nnpm test\n\n# 构建（自动处理 grammar）\nnpm run build\n\n# 清理生成的开发文件\nnpm run clean:grammar\n```\n\n更多构建说明请参考 [GRAMMAR_BUILD.md](./GRAMMAR_BUILD.md)。\n\n## Features\n\n- CommonMark 块级元素：段落、标题、分隔线、引用、代码块、列表（进行中）\n- 行内元素：强调、链接、图片、代码片段、自动链接（逐步实现）\n- 与 micromark 同步的 external tokenizer 映射；无重复实现状态机\n- 增量解析（Lezer LR） + 可扩展（后续 GFM 扩展）\n\n## Usage\n\n### Basic\n\n```ts\nimport { parser } from \"lezer-commonmark\";\n\nconst tree = parser.parse(`# Hello\\n\\nSome *text*.`);\nconsole.log(tree.toString());\n```\n\n### With CodeMirror\n\n```ts\nimport { parser } from \"lezer-commonmark\";\nimport { LRLanguage } from \"@codemirror/language\";\n\nexport const commonmarkLanguage = LRLanguage.define({\n  parser,\n  languageData: { name: \"markdown\" },\n});\n```\n\n### Tree Navigation\n\n```ts\nimport { parser, headingLine, paragraphText } from \"lezer-commonmark\";\n\nconst tree = parser.parse(`# Title\\n\\nParagraph`);\ntree.iterate({\n  enter(node) {\n    if (node.type.id === headingLine) {\n      console.log(\"Heading span:\", node.from, node.to);\n    }\n    if (node.type.id === paragraphText) {\n      console.log(\"Paragraph:\", node.from, node.to);\n    }\n  },\n});\n```\n\n### Error Handling\n\n```ts\nimport { parser } from \"lezer-commonmark\";\n\nconst tree = parser.parse(\"\u003e quote\\n\\n---\");\ntree.iterate({\n  enter(n) {\n    if (n.type.isError) console.warn(\"Error span\", n.from, n.to);\n  },\n});\n```\n\n## API\n\n### Exports\n\n- `parser` - Lezer parser 实例\n- Grammar terms - 语法节点 / token 的常量（TypeScript id）\n  - （后续）高亮与 GFM 扩展将追加导出\n\n### Types\n\n```ts\nparser.parse(input: string, fragments?: TreeFragment[], ranges?: {from: number, to: number}[]): Tree\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. 添加或调整 CommonMark fixture（放入 `tests/fixtures/`）\n4. Ensure tests pass\n5. Submit a pull request\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsec-ant%2Flezer-commonmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsec-ant%2Flezer-commonmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsec-ant%2Flezer-commonmark/lists"}