Search code examples
markdownblogshexo

How to fix the isuue that he code block can`t work in hexo blog pages?


I have just used github pages + hexo to creat my hexo blog.However,when using code block,it didn`t work at all and I wonder how to fix it. The code in md file is:

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

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

but in browser,what I saw is:

 image

I have tried many ways to fix it but failed. Btw,I use the Next theme of hexo.


Solution

  • I guess what you need is this

    {% 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 %}

    Put the above code in your md file and you'll get this.