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

Possibility to skip posts or code-sections in posts #7

Open
rndmh3ro opened this issue Oct 2, 2023 · 0 comments
Open

Possibility to skip posts or code-sections in posts #7

rndmh3ro opened this issue Oct 2, 2023 · 0 comments

Comments

@rndmh3ro
Copy link

rndmh3ro commented Oct 2, 2023

I often write blog posts that contain jinja-templating, mostly in code-sections.

The plugin will then try to parse this content , which it should not do. So I need to have a way to tell the plugin not to parse the code or post.

A simple way is to add a special string (e.g. PELICAN_NO_JINJA) into the post-content. If the plugin finds the special string, it does not parse the post at all. Here's a small patch:

diff --git a/pelican/plugins/jinja2content/jinja2content.py b/pelican/plugins/jinja2content/jinja2content.py
index 95b2064..db0c620 100644
--- a/pelican/plugins/jinja2content/jinja2content.py
+++ b/pelican/plugins/jinja2content/jinja2content.py
@@ -47,7 +47,8 @@ class JinjaContentMixin:

     def read(self, source_path):
         with pelican_open(source_path) as text:
-            text = self.env.from_string(text).render()
+            if "<!-- PELICAN_NO_JINJA -->" not in text:
+                text = self.env.from_string(text).render()

         with NamedTemporaryFile(delete=False) as f:
             f.write(text.encode())

A better way would probably to use this special string as a start and end marker where the text in between would not be parsed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant