惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
T
Threatpost
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
PCI Perspectives
PCI Perspectives
T
The Exploit Database - CXSecurity.com
Y
Y Combinator Blog
雷峰网
雷峰网
爱范儿
爱范儿
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
S
Securelist
宝玉的分享
宝玉的分享
L
LangChain Blog
O
OpenAI News
AI
AI
P
Privacy International News Feed
L
LINUX DO - 最新话题
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
M
MIT News - Artificial intelligence
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
博客园 - 【当耐特】
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
Jina AI
Jina AI
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
Webroot Blog
Webroot Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog

codeqihan的博客

现代化的开源终端-Tabby 基于Rust开发的编辑器-Edit ChatGPT Atlas使用体验 联通宽带改桥接 Chrony安装以及配置 电信跨网QoS ungoogled-chromium浏览器简介 npm的高性能替代品pnpm Nginx的安装以及配置 使用unattended-upgrades自动更新软件包 Debian使用Backports源 压缩网页体积 Debian切换至Testing/Sid版本 2024年度总结 轻量级的探针-Beszel ai.robots.txt阻止AI爬虫 甲骨文圣何塞ARM测评 公共DOH收集 com又涨价了
使用markdownlint-cli格式化Markdown文件
codeqihan · 2025-04-19 · via codeqihan的博客

简介

markdownlint是一个Markdown格式化工具,它可以对Markdown的格式进行分析,以检查是否符合规则。
markdownlint本身是一个Node.js库,没有提供CLI工具。而markdownlint-cli则为markdownlint提供了一个CLI使用方式,使markdownlint的使用更加便捷

安装

markdownlint和markdownlint-cli是Node.js程序,需要通过npm安装

1
npm install -g markdownlint-cli

使用

安装完成以后,可以提供markdownlint命令使用,例如查找除了node_modules(Node.js的依赖存储目录)以外的文件夹中的Markdown文件(静态博客可以使用这个来检查Markdown文件)

1
markdownlint **/*.md --ignore node_modules

如果发现了问题,会报错。如果想要markdownlint尝试自动修正,可以添加--fix参数

1
markdownlint **/*.md --ignore node_modules --fix

markdownlint会尝试尽可能地修正可以修正的Markdown文件
markdownlint可能会存在一些误报情况,无视即可。例如

1
source/404.md:11 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "{% p center huge, 404 %}"]

如果博客的Markdown文件存在GitHub中,可以利用GitHub Actions自动格式化Markdown文件(我是在每月1号自动格式化Markdown文件,可以修改on以在其它时间时间触发,例如推送新的提交到main分支时):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
name: Lint Markdown

on:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install markdownlint-cli
run: |
npm install -g markdownlint-cli
- name: Markdown Lint
continue-on-error: true
run: |
markdownlint **/*.md --ignore node_modules --fix
- name: Commit change & Push
continue-on-error: true
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "Markdown Lint"
git push

评论