{"id":20179681,"url":"https://github.com/lint-md/prettier-plugin","last_synced_at":"2025-04-10T04:50:41.822Z","repository":{"id":246838676,"uuid":"823441881","full_name":"lint-md/prettier-plugin","owner":"lint-md","description":"基于 lint-md 的 Prettier 格式化插件，让其符合中文编写规范。","archived":false,"fork":false,"pushed_at":"2025-03-26T01:39:49.000Z","size":2634,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T02:35:58.626Z","etag":null,"topics":["chinese","lint","lint-md","markdown","prettier"],"latest_commit_sha":null,"homepage":"https://github.com/lint-md/prettier-plugin","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/lint-md.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}},"created_at":"2024-07-03T03:42:14.000Z","updated_at":"2025-03-26T01:39:52.000Z","dependencies_parsed_at":"2024-07-22T13:27:06.047Z","dependency_job_id":"713f4d34-6608-4917-b174-f2c4588c66fb","html_url":"https://github.com/lint-md/prettier-plugin","commit_stats":null,"previous_names":["bosens-china/prettier-plugin-lint-md","lint-md/prettier-plugin"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lint-md%2Fprettier-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lint-md%2Fprettier-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lint-md%2Fprettier-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lint-md%2Fprettier-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lint-md","download_url":"https://codeload.github.com/lint-md/prettier-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161260,"owners_count":21057552,"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","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":["chinese","lint","lint-md","markdown","prettier"],"created_at":"2024-11-14T02:27:46.211Z","updated_at":"2025-04-10T04:50:41.774Z","avatar_url":"https://github.com/lint-md.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prettier-plugin-lint-md\n\n![Static Badge](https://img.shields.io/badge/MIT-License-blue) ![Static Badge](https://img.shields.io/badge/vitest-100%25-green)\n\n![logo](./img/logo.png)\n\nwhy？\n\n[Prettier 3.0](https://prettier.io/blog/2023/07/05/3.0.0.html#stop-inserting-spaces-between-chinese-or-japanese-and-western-characters) 有许多变动，其中有一条将不会自动在中英文符号插入空格提高可读性。\n\n![alt text](img/image.png)\n\n虽然从使用群体来说 Prettier 这个决定没有什么问题，不过确实也会导致编写起来会存在很多不便，所有就有了这个插件。\n\n\u003e 还有一些其他讨论：\n\u003e [Markdown: Add an option to re-enable Prettier 2.x's automatic space insertion in CJK](https://github.com/prettier/prettier/issues/15015)\n\n## 工作原理\n\n[lint-md](https://github.com/lint-md/lint-md) 是检查中文 Markdown 编写格式的工具，让你的文档更加优雅规范。\n\n它内置了许多检查：\n\n![alt text](img/image-1.png)\n\n具体配置就是[阮一峰写的中文技术文档的写作规范](https://github.com/ruanyf/document-style-guide)\n\n这个插件就是结合 Prettier 让你在编写的过程中实时修订错误。\n\n```txt\n编写 markdown  =\u003e 发现问题 =\u003e lint-md 修订 =\u003e prettier 格式化 =\u003e 输出\n```\n\n## 使用\n\n```sh\nnpm i prettier-plugin-lint-md prettier -D\n# or\nyarn add prettier-plugin-lint-md prettier -D\n# pnpm\npnpm add prettier-plugin-lint-md prettier -D\n```\n\n在 Prettier 支持的[配置文件](https://prettier.io/docs/en/configuration)，例如 `.prettierrc.mjs`\n\n```js\nexport default {\n  // ...\n  plugins: [`prettier-plugin-lint-md`],\n};\n```\n\n\u003e 上面的配置是 prettier 3.0 的配置，对于低版本的 prettier 不太清楚上面配置是否有效。\n\u003e 如果需要导入 cjs 模板的可以使用 `prettier-plugin-lint-md/dist/prettier-plugin-lint-md.cjs`。\n\n### Node 调用\n\n```ts\nimport prettierPluginLintMd, { PARSER_NAME } from 'prettier-plugin-lint-md';\nimport { format } from 'prettier';\n\nconst result = await format(code, {\n  parser: PARSER_NAME,\n  plugins: [prettierPluginLintMd],\n});\n```\n\n更多示例可以参考 [\\_\\_test\\_\\_](./__test__/) 目录。\n\n\u003e 默认 import 导入的是 es 模块，但是 cjs 模块也是在构建列表中，如果想要使用，可以通过下面的形式导入。\n\u003e\n\u003e ```js\n\u003e const prettierPluginLintMd = require('prettier-plugin-lint-md/dist/prettier-plugin-lint-md.cjs');\n\u003e // prettierPluginLintMd 有可能需要结合 prettierPluginLintMd.default 来使用，具体看构建工具实现。\n\u003e // 具体参考 [rollupjs.org/configuration-options](https://rollupjs.org/configuration-options/#output-exports)\n\u003e ```\n\n## 配置\n\n初始情况下开箱即用，如果需要对规则细致调整可以继续往下阅读。\n\nlint-md 支持 `.lintmdrc` JSON 配置文件，`prettier-plugin-lint-md` 同样也支持，默认情况下会自动启用 `.lintmdrc` 文件内的配置。\n\n如果想启用其他文件名称可以在配置文件传递 `configFile` 字段。\n\n```js\n// .prettierrc.mjs\nexport default {\n  // ...\n  plugins: [`prettier-plugin-lint-md`],\n  configFile: '.lintmdrc',\n};\n```\n\n\u003e configFile 可以是一个绝对路径也可以是相对路径，如果是相对路径会根据根目录来计算，如果绝对路径则直接启用。\n\n### 具体配置项\n\n完整配置项内容[点击查看](https://github.com/lint-md/lint-md?tab=readme-ov-file#%E8%A7%84%E5%88%99%E6%A6%82%E8%BF%B0)\n\n![alt text](img/image-1.png)\n\n之后在 `.prettierrc.mjs` 写入需要调整的配置项即可，例如禁止 `中文与英文之间需要增加空格`\n\n```js\n// .prettierrc.mjs\nexport default {\n  // ...\n  plugins: [`prettier-plugin-lint-md`],\n  'space-around-alphabet': false,\n};\n```\n\n不过需要额外注意两点：\n\n**1.** 除了 `configFile` 其他都是 `boolean`，虽然规则值本身是 `0, 1, 2` 这样的字段\n![alt text](img/image-2.png)\n但是这些是 CLI 中使用的，在 prettier 中不需要警告，只需要修复所以是 `true` 和 `false` 。\n\n**2.** 不支持 `no-long-code`，因为不支持自动修复，所以没必要存在。\n\n\u003e configFile 配置会被手动传递的规则覆盖。\n\n## 协议\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flint-md%2Fprettier-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flint-md%2Fprettier-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flint-md%2Fprettier-plugin/lists"}