抬头仰望星空,是否能发现自己的渺小。

伪斜杠青年

人们总是混淆了欲望和理想

关于 Markdown 中英文间追加空格问题

目前大范围内容所说均为 textlint-rule-ja-space-between-half-and-full-width或者 pangu.js,经过体验后发现,两者都存在问题。

pangu:对于 markdown 中的 ** 会进行误处理。

textlint:对于 markdown 语法或者标题中的内容无法处理。

经过再次检索,找到了 zhlint,其安装与使用更为简单精准,对于 Markdown 中的文本也能进行处理。

用法用量

安装( node.js ):

# install through npm
npm install zhlint -g

查看文档中的问题( 标记位置可能不准确问题 ):

# glob files, lint them, and print validation report,
# and exit with code `1` if there is any error found.
zhlint <file-pattern>

修复则直接追加 --fix

# glob files and fix their all possilbly found errors.
zhlint <file-pattern> --fix

当然也支持另存:

# lint the file and output fixed content into another file
zhlint <input-file-path> --output=<output-file-path>

更多命令可查看官网:https://zhlint.jinjiang.dev/

想先试试可访问:https://zhlint.jinjiang.dev/playground.html

后续

发现存在一些自动补全的问题,比如 toString() 会变成

function toString() { [native code] }

对于此类,目前发现只能新建文件 .zhlintcaseignore,填入相关不让处理的内容,一行一个,比如:

toString
valueOf

然后就不会去处理,同时也不会去处理相关的空格,暂未发现稳妥处理办法。(反馈后该问题已处理,详见:https://github.com/zhlint-project/zhlint/pull/160

以及部分无法准确识别和处理的问题,先检测文字是否为半角,比如”月”,”一”等字,全角半角看着无差,而 zhlint 无法识别,不过GPT 可以识别,有条件的可以尝试让 GPT 去处理文本问题,可能只是一句话的事。

其他

以上插件在 VS Code 均有对应版本,不过略微复杂,更习惯 bash 方式,于是未曾尝试。

同时顺带让 GPT 给我写了段脚本,批量处理文档:

#!/bin/bash

# 查找 content 目录下所有的 .md 文件
find ./content -type f -name "*.md" | while read -r file; do
# 执行命令
zhlint "$file" --fix
done

甚至还附带了注释。

以上。


本站由以下主机服务商提供服务支持:

0条评论

发表评论