File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -93,13 +93,23 @@ def process(self) -> Path:
9393 self .log_trace_preview (f .read ())
9494
9595 try :
96- jinja_env = create_env (self .config .template .parent )
96+ jinja_extensions = self .config .get ("jinja2_extensions" , [])
97+ if jinja_extensions :
98+ self .log_debug ("Using Jinja2 extensions: %s" , jinja_extensions )
99+ jinja_env = create_env (
100+ templates_dir = self .config .template .parent ,
101+ extensions = jinja_extensions ,
102+ )
97103 template = jinja_env .get_template (self .config .template .name )
98104 except TemplateNotFound as exc :
99105 raise SVGTemplateError (
100106 "Failed to load template for page "
101107 f"{ self .number } ({ self .config .name } ): { exc } "
102108 ) from exc
109+ except TemplateError as exc :
110+ raise SVGTemplateError (
111+ f"Template error for page { self .number } ({ self .config .name } ): { exc } "
112+ ) from exc
103113
104114 template_context = prepare_template_context (
105115 self .config ,
Original file line number Diff line number Diff line change @@ -39,16 +39,17 @@ def replacer(match: re.Match[str]) -> str:
3939 return rendered
4040
4141
42- def create_env (templates_dir : Path | None = None ) -> jinja2 .Environment :
42+ def create_env (
43+ templates_dir : Path | None = None , extensions : list [str ] | None = None
44+ ) -> jinja2 .Environment :
4345 """Create and configure the Jinja environment."""
4446 if templates_dir is None :
4547 raise ValueError ("templates_dir is required" )
4648
4749 env = jinja2 .Environment (
4850 loader = jinja2 .FileSystemLoader (str (templates_dir )),
4951 autoescape = jinja2 .select_autoescape (),
50- # FIXME: extensions configurable
51- extensions = ["jinja2.ext.do" ],
52+ extensions = extensions or [],
5253 )
5354 env .template_class = HighlightingTemplate
5455 return env
You can’t perform that action at this time.
0 commit comments