
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
fix-cjk-linebreak
Advanced tools
修复 HTML 源文件中由于换行导致的中日韩 (CJK) 符号和标点之间的多余空格。
HTML 规范没有明确说明如何渲染源文件中的换行符,它只是简单地将其视为一个空格。对于西方语言来说,这种处理方式是可以的,因为每个单词之间应该有一个空格。但对于中日韩语言,通常两个 CJK 符号或标点之间没有空格。因此,HTML 页面源文件中的换行符会导致不必要的额外空格。
例如,考虑以下 HTML 源代码:
<p>1. 测试样例:这是源码中的第一行,以中文字符结束
这是源码中的第二行,以中文字符开头</p>
<p>1. 正确结果:这是源码中的第一行,以中文字符结束这是源码中的第二行,以中文字符开头</p>
第一个 <p>
元素中的文本会在源代码中的两行间有一个不必要的额外空格。
我们使用 JavaScript 来修改 <p>
元素的内部 HTML,移除由换行符引入的所有额外空格。
此脚本依赖于以下包(已内置到 UMD 版本中):
npm install fix-cjk-linebreak
你也可以手动安装脚本:
// ESM
import fixCJKLinebreak from 'fix-cjk-linebreak';
// 自动修复页面中的所有段落
fixCJKLinebreak.autoFix();
// 或者手动修复特定元素下的段落
document.addEventListener('DOMContentLoaded', function() {
fixCJKLinebreak.fix(document.getElementById('content'));
});
// 具名导入
import { fix, autoFix } from 'fix-cjk-linebreak';
// CommonJS
const { fix, autoFix } = require('fix-cjk-linebreak');
// 使用导入的函数
autoFix();
// 或
document.addEventListener('DOMContentLoaded', function() {
fix(document.getElementById('content'));
});
在你的网页的 <head>..</head>
部分添加以下代码:
<!-- UMD 版本已包含所有依赖 -->
<script src="https://unpkg.com/fix-cjk-linebreak"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
fixCJKLinebreak.fix(document.body);
});
</script>
或者使用自动修复功能:
<!-- UMD 版本已包含所有依赖 -->
<script src="https://unpkg.com/fix-cjk-linebreak"></script>
<script>
fixCJKLinebreak.autoFix();
</script>
fix
函数接受一个参数,该参数应该是一个 DOM 元素。该函数将修复参数 DOM 元素下的所有 <p>
元素,移除由源代码中的换行符引入的 CJK 字符之间的额外空格。
请查看 test
目录下的测试页面以了解使用示例。
该脚本已在以下浏览器中测试:
GPL-2.0
FAQs
修复 HTML 源码中 CJK 字符和标点之间由于换行导致的多余空格
The npm package fix-cjk-linebreak receives a total of 7 weekly downloads. As such, fix-cjk-linebreak popularity was classified as not popular.
We found that fix-cjk-linebreak demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.