本帖最后由 T4DNA 于 2024-2-21 20:42 编辑
wangeditor的代码高亮显示问题,我在前端使用了prism.js,但是我发现wangeditor生成的代码块没有携带span标签,导致无法正常高亮,有没有懂这个的朋友?
正常生成的文本:
[HTML] 纯文本查看 复制代码 <code class="language-javascript"><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token parameter">a</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> a <span class="token operator">===</span> <span class="token string">'number'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> a <span class="token operator">+</span> <span class="token number">100</span> <span class="token comment">// comments</span>
<span class="token punctuation">}</span>
<span class="token keyword">return</span> <span class="token number">0</span>
<span class="token punctuation">}</span></code>
我生成的文本:
[HTML] 纯文本查看 复制代码 <code class="language-html"><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="static/css/utils.css">
<link rel="stylesheet" href="static/css/article.css">
<link rel="stylesheet" href="static/css/prism.css">
<link rel="icon" href="static/images/logo2.png">
<script src="static/js/jquery-3.7.1.min.js"></script>
<title></title>
</head>
<body>
<header>
<div class="logoContainer">
<a href="/">
<img src="static/images/logo2.png" alt="">
penguin
</a>
</div>
<div class="linkContainer">
<span>XXXXXX:</span>
<a href="https://XXXXXXXXXX">@XXXXXXX</a>
<span style="margin-left: 20px;">XXXXXXX:</span>
<a href="https://XXXXXXXXXX">@XXXXXXXX</a>
</div>
</header>
<div class="mainPage">
<div class="mainContentContainer">
<div class="articleTitle"></div>
<div class="articleDate"></div>
<div class="articleContent"></div>
</div>
</div>
<script src="static/js/article.js"></script>
<script src="static/js/prism.js"></script>
</body>
</html></code>
差别好像就在每一个关键字都有span上,我生成的没有span标签包裹关键字,这是为什么? |