hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.86k stars 4.76k forks source link

{% %} should not be rendered in a post #3346

Closed yifei325325 closed 4 years ago

yifei325325 commented 5 years ago

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

gautamz07 commented 5 years ago

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

yifei325325 commented 5 years ago

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

yifei325325 commented 5 years ago

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

yoshinorin commented 5 years ago

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

We need investigation.

yifei325325 commented 5 years ago

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

yoshinorin commented 5 years ago

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

yifei325325 commented 5 years ago

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.

52Heartz commented 5 years ago

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

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

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

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

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

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

SukkaW commented 4 years ago

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

SukkaW commented 4 years ago

Could be fixed by #4171.

stevenjoezhang commented 4 years ago

Relevant issues: https://github.com/hexojs/hexo/issues/546 https://github.com/hexojs/hexo/issues/2030 https://github.com/hexojs/hexo/issues/2522 https://github.com/hexojs/hexo/issues/3259 https://github.com/hexojs/hexo/issues/3543 https://github.com/hexojs/hexo/issues/4092 https://github.com/hexojs/hexo/issues/4109

curbengh commented 4 years ago

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.