reveal-code-focus 项目教程
1. 项目的目录结构及介绍
reveal-code-focus/
├── demo/
│ ├── index.html
│ └── ...
├── dist/
│ ├── reveal-code-focus.js
│ └── ...
├── src/
│ ├── reveal-code-focus.js
│ └── ...
├── .gitignore
├── LICENSE
├── package.json
├── README.md
└── ...
- demo/: 包含项目的演示文件,如
index.html
。 - dist/: 包含构建后的文件,如
reveal-code-focus.js
。 - src/: 包含源代码文件,如
reveal-code-focus.js
。 - .gitignore: Git 忽略文件列表。
- LICENSE: 项目许可证。
- package.json: 项目的 npm 配置文件。
- README.md: 项目说明文档。
2. 项目的启动文件介绍
项目的启动文件主要是 demo/index.html
,它包含了 Reveal.js 的初始化和 reveal-code-focus 插件的加载。以下是 index.html
的部分代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>reveal-code-focus demo</title>
<link rel="stylesheet" href="../node_modules/reveal.js/css/reveal.css">
<link rel="stylesheet" href="../node_modules/reveal.js/css/theme/solarized.css">
<link rel="stylesheet" href="../node_modules/reveal.js/lib/css/zenburn.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown>
<script type="text/template">
## Demo
```js
// Useless comment
alert('hi');
```
<p class="fragment" data-code-focus="1">This focuses on the comment</p>
<p class="fragment" data-code-focus="1-2">Another fragment</p>
</script>
</section>
</div>
</div>
<script src="../node_modules/reveal.js/js/reveal.js"></script>
<script src="../dist/reveal-code-focus.js"></script>
<script>
Reveal.initialize({
dependencies: [
{ src: '../node_modules/reveal.js/plugin/markdown/marked.js' },
{ src: '../node_modules/reveal.js/plugin/markdown/markdown.js' },
{ src: '../node_modules/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: '../dist/reveal-code-focus.js', async: true, callback: function() { RevealCodeFocus(); } }
]
});
</script>
</body>
</html>
3. 项目的配置文件介绍
项目的配置文件主要是 package.json
,它包含了项目的依赖、脚本和其他元数据。以下是 package.json
的部分内容:
{
"name": "reveal-code-focus",
"version": "1.0.0",
"description": "A Reveal.js plugin that allows focusing on specific lines of code blocks",
"main": "dist/reveal-code-focus.js",
"scripts": {
"build": "webpack",
"demo": "http-server demo"
},
"dependencies": {
"reveal.js": "^4.0.0",
"highlight.js": "^10.5.0"
},
"devDependencies": {
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bnjmnt4n/reveal-code-focus.git"
},
"keywords": [
"reveal.js",
"code",
"focus"
],
"