Hexo-Renderer-Markdown-It-Plus 使用教程
1. 项目的目录结构及介绍
hexo-renderer-markdown-it-plus/
├── lib/
│ ├── index.js
│ └── ...
├── test/
│ ├── index.js
│ └── ...
├── .eslintignore
├── .eslintrc
├── .gitattributes
├── .gitignore
├── .mocharc.yml
├── LICENSE
├── README.md
├── index.js
├── package.json
└── yarn.lock
- lib/: 包含项目的主要逻辑文件。
- test/: 包含项目的测试文件。
- .eslintignore: ESLint 忽略配置文件。
- .eslintrc: ESLint 配置文件。
- .gitattributes: Git 属性配置文件。
- .gitignore: Git 忽略配置文件。
- .mocharc.yml: Mocha 测试框架配置文件。
- LICENSE: 项目许可证文件。
- README.md: 项目说明文件。
- index.js: 项目的入口文件。
- package.json: 项目的依赖和脚本配置文件。
- yarn.lock: Yarn 包管理器锁定文件。
2. 项目的启动文件介绍
项目的启动文件是 index.js
,它作为入口文件,负责初始化和配置 Markdown-it 渲染引擎。以下是 index.js
的主要内容:
const markdownIt = require('markdown-it');
const markdownItPlus = require('./lib/index');
module.exports = function(hexo) {
const config = hexo.config.markdown || {};
const md = markdownIt(config);
markdownItPlus(md, hexo);
hexo.extend.renderer.register('md', 'html', function(data, options) {
return md.render(data.text, options);
});
};
- markdownIt: 引入 Markdown-it 库。
- markdownItPlus: 引入自定义的 Markdown-it 插件。
- module.exports: 导出函数,用于 Hexo 的渲染器注册。
3. 项目的配置文件介绍
项目的配置文件主要是 package.json
,它包含了项目的依赖、脚本和其他元数据。以下是 package.json
的主要内容:
{
"name": "hexo-renderer-markdown-it-plus",
"version": "1.0.0",
"description": "Markdown-it is a markdown parser done right. A faster and CommonMark compliant alternative for Hexo.",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus.git"
},
"keywords": [
"hexo",
"markdown",
"markdown-it",
"renderer"
],
"author": "CHENXCHEN",
"license": "MIT",
"bugs": {
"url": "https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus/issues"
},
"homepage": "https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus#readme",
"dependencies": {
"markdown-it": "^12.0.0",
"markdown-it-plus": "^1.0.0"
},
"devDependencies": {
"mocha": "^9.0.0"
}
}
- name: 项目名称。
- version: 项目版本。
- description: 项目描述。
- main: 入口文件。
- scripts: 脚本命令,如测试命令
npm test
。 - repository: 项目仓库地址。
- keywords: 项目关键词。
- author: 项目作者。
- license: 项目许可证。
- bugs: 问题跟踪地址。
- homepage: 项目主页。
- dependencies: 项目依赖。
- devDependencies: 开发依赖