Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yifei325325 opened this issue Nov 8, 2018 · 12 comments · Fixed by #4352
Closed

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

yifei325325 opened this issue Nov 8, 2018 · 12 comments · Fixed by #4352
Labels
bug Something isn't working
Milestone

Comments

@yifei325325
Copy link

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
Copy link
Contributor

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

@yifei325325
Copy link
Author

yifei325325 commented Nov 8, 2018

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
Copy link
Author

yifei325325 commented Nov 8, 2018

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

@yoshinorin
Copy link
Member

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

We need investigation.

@yifei325325
Copy link
Author

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
Copy link
Member

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

@yoshinorin yoshinorin added the bug Something isn't working label Nov 9, 2018
@yifei325325
Copy link
Author

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
Copy link

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

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

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

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

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

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

@SukkaW
Copy link
Member

SukkaW commented Mar 4, 2020

The issue is related to post rendering process, which I had a look at during the review of PR #4161.

The post rendering process could be described as follows: #4161 (comment)

@SukkaW
Copy link
Member

SukkaW commented Mar 4, 2020

Could be fixed by #4171.

@stevenjoezhang
Copy link
Member

stevenjoezhang commented Mar 4, 2020

Relevant issues:
#546
#2030
#2522
#3259
#3543
#4092
#4109

SukkaW added a commit to SukkaW/hexo that referenced this issue Mar 4, 2020
@curbengh
Copy link
Contributor

curbengh commented Mar 5, 2020

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.

@stevenjoezhang stevenjoezhang changed the title hexo 在markdown文档中出现{% %}语法会报错,提示“Template render error: (unknown path) ” {% %} should not be rendered in a post Jun 7, 2020
@SukkaW SukkaW added this to the 5.0.0 milestone Jun 10, 2020
@stevenjoezhang stevenjoezhang linked a pull request Jun 10, 2020 that will close this issue
2 tasks
SukkaW added a commit that referenced this issue Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants