Hexo: {% %} should not be rendered in a post

Created on 8 Nov 2018  ·  12Comments  ·  Source: hexojs/hexo

Environment Info

Node version(node -v):

Your site _config.yml (Optional):

Your theme _config.yml (Optional):

Hexo and Plugin version(npm ls --depth 0):

For BUG

比如新建一个名为“test.md”的文档,在里面包含以下这句话,
测试测试测试{% test %}测试测试
在使用hexo g 命令时就会报错,提示Template render error: (unknown path)
而如果把上面的文字改成
测试测试测试

{% test %}

测试
这样使用hexo g 命令就会通过。

而在markdown 编辑器中 ,测试测试测试{% test %}测试测试 这样的写法是支持的,预览也不会出任何问题。

For question

For feature request

bug

Most helpful comment

我今天也遇到了这个问题,我对问题的理解以及解决方法如下:

首先,{% test %} 是一个未知的标签,Hexo 是不会支持的,支持的标签可以参考这个官方文档:标签插件(Tag Plugins)

另外,即使这个标签是 Hexo 支持的,那么 {% xxx %} 和 {% endxxx %} 需要配合使用,一个标志开始,一个标志结束,不能只用一个。

只使用一个会报错 unexpected end of file。如果使用错误的标签名会报错 unknown block tag: xxx

另外,如果文章中出现单独的 {{ 或者 }} 也会报错,原因也是因为 {{ 和 }} 被 Hexo 当作标签的标志来处理了。

更多的内容,可以参考我博客的这篇文章:Hexo 的 Template render error 错误

All 12 comments

I suppose your not suppose to have ejs code inside your .md file , are to trying to showcase a code snippet ?

Thanks for your reply, now i try to explain my issue in English.

when i have a markdown file like test.md, all the markdown syntax passed the "hexo g" command. but when i include the statement like this

codes for example {% test code %} code for example

ignores the dash please. the two " ` " means ,there is a code inside.

when i try to use "hexo g" command to compile the file to html file. it shows the error like "Template render error: (unknown path) ". But when i delete this statement, everything goes fine.
How odd!

image

but when i write the code like this
image
use the "hexo g" command , every thing goes well. @gautamz07

Same problem reported at (#2515 )
But, it seems solved (#2461)

We need investigation.

Same problem reported at (#2515 )
But, it seems solved (#2461)

We need investigation.

thank for your reply, but i think they fixed this bug on 31 March 2017.
and my hexo version is 3.7.1 which released on 7 months ago.
image

image

Yup, I know. I reproduce it v3.8.0
I think, this problem is a regression bug or not fixed in #2461

Yup, I know. I reproduce it v3.8.0
I think, this problem is a regression bug or not fixed in #2461

Thanks, I got it. hope it will be fixed on next release version.

我今天也遇到了这个问题,我对问题的理解以及解决方法如下:

首先,{% test %} 是一个未知的标签,Hexo 是不会支持的,支持的标签可以参考这个官方文档:标签插件(Tag Plugins)

另外,即使这个标签是 Hexo 支持的,那么 {% xxx %} 和 {% endxxx %} 需要配合使用,一个标志开始,一个标志结束,不能只用一个。

只使用一个会报错 unexpected end of file。如果使用错误的标签名会报错 unknown block tag: xxx

另外,如果文章中出现单独的 {{ 或者 }} 也会报错,原因也是因为 {{ 和 }} 被 Hexo 当作标签的标志来处理了。

更多的内容,可以参考我博客的这篇文章:Hexo 的 Template render error 错误

The issue is related to post rendering process, which I had a look at during the review of PR https://github.com/hexojs/hexo/pull/4161.

The post rendering process could be described as follows: https://github.com/hexojs/hexo/pull/4161#issuecomment-591802138

Could be fixed by #4171.

the example given in #3259,

`{{ 1+1 }}`

will be rendered to, (which is not desired)

<code>2</code>

A workaround is to use {% raw %},

`{% raw %}{{ 1+1 }}{% endraw %}`

that will be rendered to the expected result,

<code>{{ 1+1 }}</code>

but if a post has many template examples, that's a lot of typing.

However, triple backtick does work as expected though,

```
{{ 1+1 }}
```

which will rendered to code highlighted "{{ 1+1 }}".

TL;DR nunjucks template is not rendered in triple backtick (as expected), but rendered in single backtick (not expected).

@SukkaW @stevenjoezhang @seaoak

I understand #4171 has already include many fixes, but I wonder if it can help #3259.

Was this page helpful?
0 / 5 - 0 ratings