-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-highlight.html
72 lines (60 loc) · 2.57 KB
/
code-highlight.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wangEditor code highlight</title>
<link href="https://cdn.bootcdn.net/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
<link href="./css/layout.css" rel="stylesheet">
<script src="./js/custom-elem.js"></script>
<!-- 引入 prism css -->
<!-- <link href="https://cdn.jsdelivr.net/npm/prismjs@latest/themes/prism.css" rel="stylesheet"> -->
<link href="https://unpkg.com/prismjs@latest/themes/prism.css" rel="stylesheet">
</head>
<body>
<demo-nav title="wangEditor code highlight"></demo-nav>
<div class="page-container">
<div class="page-left">
<demo-menu></demo-menu>
</div>
<div class="page-right">
<!-- 静态 -->
<div style="border: 1px solid #ccc; padding: 0 10px; border-radius: 5px;">
<p>wangEditor 输出的 Javascript 代码:</p>
<pre><code class="language-javascript">const a = 100;
function fn(x) { return x + 10 };
// 注释
</code></pre>
<p>wangEditor 输出的 HTML 代码:</p>
<pre><code class="language-html"><div>text1</div></code></pre>
</div>
<!-- 动态 -->
<div id="content-container"
style="border: 1px solid #ccc; padding: 0 10px; margin-top: 15px; border-radius: 5px;"></div>
<div style="margin-top: 15px;">
<button id="btn-render">Dynamic render HTML</button>
</div>
</div>
</div>
<!-- 引入 prism js -->
<!-- <script src="https://cdn.jsdelivr.net/npm/prismjs@latest/prism.min.js"></script> -->
<script src="https://unpkg.com/prismjs@latest/prism.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/prismjs@latest/components/prism-core.min.js"></script> -->
<script src="https://unpkg.com/prismjs@latest/components/prism-core.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/prismjs@latest/plugins/autoloader/prism-autoloader.min.js"></script> -->
<script src="https://unpkg.com/prismjs@latest/plugins/autoloader/prism-autoloader.js"></script>
<script>
const html = `<p>wangEditor 输入的 Javascript 代码:</p><pre><code class="language-javascript">function fn(a) {
if (typeof a === 'number') {
return a + 100 // comments
}
return 0
}</code></pre><p><br></p>`
document.getElementById('btn-render').addEventListener('click', () => {
document.getElementById('content-container').innerHTML = html
Prism.highlightAll()
})
</script>
</body>
</html>