rehype-sanitize 项目教程
rehype-sanitizeplugin to sanitize HTML项目地址:https://gitcode.com/gh_mirrors/re/rehype-sanitize
1、项目的目录结构及介绍
rehype-sanitize/
├── .github/
│ └── workflows/
├── lib/
│ └── index.js
├── .editorconfig
├── .gitignore
├── .npmrc
├── .prettierignore
├── index.js
├── LICENSE
├── package.json
├── README.md
├── test.js
└── tsconfig.json
- .github/workflows/: 包含 GitHub Actions 的工作流配置文件。
- lib/: 包含项目的主要代码文件。
- .editorconfig: 编辑器配置文件,用于统一代码风格。
- .gitignore: Git 忽略文件配置。
- .npmrc: npm 配置文件。
- .prettierignore: Prettier 忽略文件配置。
- index.js: 项目的入口文件。
- LICENSE: 项目的许可证文件。
- package.json: 项目的 npm 配置文件,包含依赖、脚本等信息。
- README.md: 项目的说明文档。
- test.js: 项目的测试文件。
- tsconfig.json: TypeScript 配置文件。
2、项目的启动文件介绍
项目的启动文件是 index.js
。这个文件是 rehype-sanitize 插件的入口点,负责初始化和配置插件。
// index.js
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import {read} from 'to-vfile'
const file = await unified()
.use(rehypeParse)
.use(rehypeSanitize)
.use(rehypeStringify)
.process(await read('index.html'))
console.log(String(file))
3、项目的配置文件介绍
- package.json: 这个文件包含了项目的元数据和依赖项。以下是一些关键字段:
{
"name": "rehype-sanitize",
"version": "6.0.0",
"description": "rehype plugin to sanitize HTML",
"main": "index.js",
"type": "module",
"scripts": {
"test": "node test.js"
},
"dependencies": {
"rehype-parse": "^8.0.0",
"rehype-stringify": "^8.0.0",
"to-vfile": "^7.0.0",
"unified": "^10.0.0"
},
"devDependencies": {
"prettier": "^2.0.0"
}
}
- tsconfig.json: TypeScript 配置文件,用于编译 TypeScript 代码。
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
通过以上介绍,您可以更好地理解和使用 rehype-sanitize 项目。希望这篇教程对您有所帮助!
rehype-sanitizeplugin to sanitize HTML项目地址:https://gitcode.com/gh_mirrors/re/rehype-sanitize