Hexo博客开发之——Markdown中出现“{{”号解析报错

一 现象描述

最近写了一篇文章,在执行hexo g指令时生成文章预览时,会发生错误,错误信息如下:

1
2
3
4
Unhandled rejection Nunjucks Error: _posts/xxxxxxxxxxx.md [Line 27, Column 114] unexpected token: }}
    =====               Context Dump               =====
    === (line number probably different from source) ===
  22 | <!--code3-->

二 原因分析

2.1 分析过程

  • 将本篇文章删除后,hexo g 能正常执行,说明是本篇文章引起的问题
  • 将本篇文章的内容删除后,hexo指令能正常执行,说明不是头部categories和tags引起的问题
  • 确定是文章内容引起的问题,根据错误信息,逐步缩小查找范围,最终确定是"{{"引起的错误

2.3 原因搜索

2.4 原因解释(hexo troubleshooting)

1
2
3
4
5
6
7
8
9
10
Escape Contents
Hexo uses Nunjucks to render posts (Swig was used in older version, which share a similar syntax). Content wrapped with {{ }} or {% %} will get parsed and may cause problems. You can skip the parsing by wrapping it with the raw tag plugin, single backtick `{{ }}` or triple backtick.
Alternatively, Nunjucks tags can be disabled through the renderer’s option (if supported), API or front-matter.

{% raw %}
Hello {{ world }}
{% endraw %}
​```
Hello {{ world }}
​```

三 解决办法

  • 修改前

    1
    
    "{{}}"
    
  • 修改后

    1
    
    {% raw %}"{{}}"{% endraw %}
    

四 参考

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值