npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prettier-plugin-lint-md

v1.0.1

Published

prettier 格式化插件,让其符合中文编写规范。

Downloads

415

Readme

prettier-plugin-lint-md

logo

why?

Prettier 3.0 有需要变动,其中有一条将不会自动在中英文符号插入空格提高可读性。

alt text

虽然从使用群体来说 Prettier 这个决定没有什么问题,不过确实也会导致编写起来会存在很多不便,所有就有了这个插件。

还有一些其他讨论: Markdown: Add an option to re-enable Prettier 2.x's automatic space insertion in CJK

工作原理

lint-md 是检查中文 Markdown 编写格式的工具,让你的文档更加优雅规范。

它内置了许多检查:

alt text

具体配置就是阮一峰写的中文技术文档的写作规范

这个插件就是结合 Prettier 让你在编写的过程中实时修订错误。

编写md  => 发现问题 => lint-md 修订 => prettier 格式化 => 输出

使用

npm i prettier-plugin-lint-md prettier -D
# or
yarn i prettier-plugin-lint-md prettier -D
# pnpm
pnpm add prettier-plugin-lint-md prettier -D

在 Prettier 支持的配置文件,例如 .prettierrc.mjs

export default {
  // ...
  plugins: [`prettier-plugin-lint-md`],
};

上面的配置是 prettier 3.0 的配置,对于低版本的 prettier 不太清楚上面配置是否有效。 如果需要导入 cjs 模板的可以使用 prettier-plugin-lint-md/dist/prettier-plugin-lint-md.cjs

Node 调用

import prettierPluginLintMd, { PARSER_NAME } from 'prettier-plugin-lint-md';
import { format } from 'prettier';

const result = await format(code, {
  parser: PARSER_NAME,
  plugins: [prettierPluginLintMd],
});

更多使用场景可以参考 test 目录。

默认 import 导入的是 es 模块,但是 cjs 模块也是在构建列表中,如果想要使用,可以通过下面的形式导入。

const prettierPluginLintMd = require('prettier-plugin-lint-md/dist/prettier-plugin-lint-md.cjs');
// prettierPluginLintMd 有可能需要结合 prettierPluginLintMd.default 来使用,具体看构建工具实现。
// 具体参考 [rollupjs.org/configuration-options](https://rollupjs.org/configuration-options/#output-exports)

配置

初始情况下已经包含了预设规则,所以确定你有需要调整的规则可以继续往下阅读。

lint-md 支持 .lintmdrc JSON 文件,prettier-plugin-lint-md 同样也支持,只需要在配置文件传递 configFile 即可。

// .prettierrc.mjs
export default {
  // ...
  plugins: [`prettier-plugin-lint-md`],
  configFile: '.lintmdrc',
};

默认会自动检测 .lintmdrc 文件,所以默认情况下你可以不需要传递,但是如果你想定义其它名称则需要传递,.lintmdrc 可以是一个绝对路径也可以是相对路径。

还有上面列举的一系列规则也同样支持,在 .prettierrc.mjs 直接写入即可,例如

// .prettierrc.mjs
export default {
  // ...
  plugins: [`prettier-plugin-lint-md`],
  'space-around-alphabet': false,
};

这里需要注意,除了 configFile 其他都是 boolean,虽然规则本身的值是下面 alt text

但是这些是 CLI 中使用的,在 prettier 中则需要 truefalse 即可。

configFile 配置会被手动传递的覆盖。

协议

MIT License