【问题标题】:How to fix the isuue that he code block can`t work in hexo blog pages?如何解决他的代码块无法在 hexo 博客页面中工作的问题?
【发布时间】:2023-03-07 08:12:01
【问题描述】:

我刚刚使用 github pages + hexo 创建了我的 hexo 博客。但是,当使用代码块时,它根本不起作用,我想知道如何修复它。 md文件中的代码是:

```js
var allp=$("div p");
allp.attr("class",function(i,n){
           return Number(n)+1;
      });
```      

```js
allp.each(function(){
        console.log(this);
        });
```

但在浏览器中,我看到的是:

我尝试了很多方法来修复它,但都失败了。顺便说一句,我用的是 hexo 的 Next 主题。

【问题讨论】:

    标签: markdown blogs hexo


    【解决方案1】:

    我猜你需要的是这个

    {% codeblock code snippet 1 lang:js %}
    var allp=$("div p");
    allp.attr("class",function(i,n){
               return Number(n)+1;
          });
    {% endcodeblock %}     
    
    {% codeblock code snippet 2 lang:js %}
    allp.each(function(){
            console.log(this);
            });
    {% endcodeblock %}

    把上面的代码放到你的md文件中,你会得到this

    【讨论】:

      【解决方案2】:

      也许您可以尝试以下步骤:
      1. 在主题的_config.yml 中启用高亮,尤其是'auto_detect';

       highlight:
            enable: true
            auto_detect: true
            line_number: true
            tab_replace:
      
      1. 通过hexo clean清理缓存;

      2. 通过hexo s重启服务器;

      【讨论】:

        猜你喜欢
        • 2021-04-06
        • 1970-01-01
        • 2018-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多