分享 171 2

    prism.js 代码高亮

    AI摘要:本文介绍了如何使用 Prism.js 实现代码高亮功能。首先,在 HTML 的 head 中插入 Prism.js 的引用和样式表链接。然后,在 pjax 回调函数中调用 Prism.highlightAll() 函数来实现代码高亮。

    代码

    在 head 中插入

    <script src="https://cdnjs.sgcd.net/code-highlight/js/prism.js"></script>
    <link rel="stylesheet" href="https://cdnjs.sgcd.net/code-highlight/css/prism.css"  />

    pjax回调

    $(document).on('pjax:end', function() {
      // 回调函数中调用 Prism 的高亮函数
      Prism.highlightAll();
    });
    
    老孙
    资深网民孙先生

    Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /www/wwwroot/imsun.org/usr/themes/typecho-theme-farallon/comments.php on line 4
    1. Kevin
      2024-04-07 16:15

      你这AI摘要的样式我去抄一下哈哈哈

        1. 老孙
          2024-04-08 07:53
          @Kevin

          这个是插件自带的哈🤣