Closed zeigerpuppy closed 3 years ago
Welcome to this project and thank you!' first issue
Same problem I've met before. I think the documentation might help.
@HuangFuSL is right: the Jinja2 engine in mkdocs-macros presumably tried to interpret {% Vimeo ID}
as a Jinja2 directive.
As mentioned in the doc, the template engine tries to interpret any piece of code it finds, including in the code blocs. This is to allow you to generate "on the fly" code blocks (e.g. config files that reflect actual values).
So you would need to "escape" that code, one way or the other.
{% raw %}
and {% endraw %}
). If you have a static code block (never changes), you would just wrap your code block with it.{{ "{% Vimeo ID}" }}
Maybe we can add an option to mkdocs.yml or an ignore file similar with .gitignore controlling files to be ignored? This solution is more convenient for resolving such issues in large projects.
皇甫硕龙
From: Laurent Franceschetti @.> Sent: Friday, April 16, 2021 3:09:29 PM To: fralau/mkdocs_macros_plugin @.> Cc: HuangFuSL @.>; Mention @.> Subject: Re: [fralau/mkdocs_macros_plugin] macros plugin interprets syntax in code blocks as macro tags - fails to build (#78)
@HuangFuSLhttps://github.com/HuangFuSL is right: the Jinja2 engine in mkdocs-macros presumably tried to interpret {% Vimeo ID} as a Jinja2 directive.
As mentioned, the template engine tries to interpret any piece of code it finds, including in the code blocs. This is to allow you to generate "on the fly" code blocks (e.g. config files that reflect actual values).
― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/fralau/mkdocs_macros_plugin/issues/78#issuecomment-820966056, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANQA7UNCPQVY7JUVAY2BDALTI7PCTANCNFSM43AJG2EA.
@HuangFuSL I've thought about solutions of that type.
I am not sure that file-level granularity would be sufficient (unless you have an argument for it).
For code blocks: from a user's perspective, it's perhaps more intuitive to think that inline code or a code block will not be interpreted. It's easier said than done, however, because it involves parsing the markdown file to ignore those items. It's perhaps doable, but it's not going to be done in five minutes.
But I'm open to suggestions on how to make life easier for projects, by avoiding these conflicts of syntax.
Should we open a discussion item for that?
Just a bit of feedback regarding the different methods. Method 1 would be the simplest to use as it can be applied in place where such markdown sequences exist. Unfortunately it doesn't work
{{ "{% Vimeo ID}" }}
: throws same error as before jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'Vimeo'.
also tried {{ "'{% Vimeo ID}'" }}
and {{ '{{"% Vimeo ID"}}' }}
but these also don't work.
the raw
method also seems to fail with the same error:
{% raw %}
`{% Vimeo ID}`
{% endraw %}
- macros:
j2_block_start_string: '[[%'
j2_block_end_string: '%]]'
j2_variable_start_string: '[['
j2_variable_end_string: ']]'
This method worked. It's one I can live with as it keeps the markdown clean. Thanks for pointing me in the right direction.
Glad that solution 3 worked.
I am puzzled on why methods 1 and 2 failed. Could you perhaps give me a minimal example of your markdown file, so that I can test it here?
Sure, here's a minimal test with examples (I am using mkdocs-material)
---
template: overrides/main.html
---
# Test
`{% Vimeo ID}`
`{{ "{% Vimeo ID}" }}`
{% raw %}
`{% Vimeo ID}`
{% endraw %}
@zeigerpuppy Strange. The two following expressions worked for me:
`{{ "{% Vimeo ID}" }}`
{% raw %}
`{% Vimeo ID}`
{% endraw %}
(I did not try with a template, but I don't see that it would make a difference?)
@zeigerpuppy We will attempt to fix this in the following way (See discussion in #79):
If you want a page not to be interpreted as Jinja2 by mkdocs-macros, then add an ignore_macros: true
declaration in the YAML header of the page.
Later if you want to add Jinja2 statements:
{% raw %}
and {% endraw %}
ignore_macros
to false or remove the directive.@zeigerpuppy and @HuangFuSL :
Could you let me know if the new version:
Yeah, this version works for me. And this extension helps a lot for my project. Thank you! ❤️
皇甫硕龙
From: Laurent Franceschetti @.> Sent: Thursday, April 22, 2021 3:57:10 PM To: fralau/mkdocs_macros_plugin @.> Cc: HuangFuSL @.>; Mention @.> Subject: Re: [fralau/mkdocs_macros_plugin] macros plugin interprets syntax in code blocks as macro tags - fails to build (#78)
@zeigerpuppyhttps://github.com/zeigerpuppy and @HuangFuSLhttps://github.com/HuangFuSL :
Could you let me know if the new version:
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/fralau/mkdocs_macros_plugin/issues/78#issuecomment-824627357, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANQA7ULZOLISSWL5U6IYULDTJ7JFNANCNFSM43AJG2EA.
I have a markdown document where I am detailing syntax.
In particular, I am using the description:
{% Vimeo ID}
With the mkdocs_macro_plugin enabled, this syntax which is contained in a code block fails to build. I believe that the plugin is trying to interpret the
{%
as a tag.Would it be possible to exclude the macro plugin parsing the contents of code blocks?
The build error is:
INFO - [macros] - ERROR # Macro Rendering Error
TemplateSyntaxError: Encountered unknown tag 'Vimeo'.