Skip to content

Commit

Permalink
Jinja2 autoescape demo
Browse files Browse the repository at this point in the history
  • Loading branch information
haxtibal committed Jul 18, 2024
1 parent 0832873 commit 6039713
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def __init__(
self.error_message: Optional[str] = None

def render_screen(self, jinja_environment: Environment):
template = jinja_environment.get_template("screens/git/index.jinja")
template = jinja_environment.overlay(autoescape=False).get_template(
"screens/git/index.jinja"
)
return template.render(view_object=self)

def render_url(self, url: str):
Expand Down
1 change: 1 addition & 0 deletions strictdoc/export/html/html_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self):
loader=FileSystemLoader(environment.get_path_to_html_templates()),
undefined=StrictUndefined,
extensions=[AssertExtension],
autoescape=True,
)

def jinja_environment(self) -> Environment:
Expand Down
4 changes: 3 additions & 1 deletion strictdoc/export/html/renderers/markup_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# mypy: disable-error-code="attr-defined,no-untyped-call,no-untyped-def,var-annotated"
from typing import Optional, Type, Union

from markupsafe import Markup

from strictdoc.backend.sdoc.models.anchor import Anchor
from strictdoc.backend.sdoc.models.document import SDocDocument
from strictdoc.backend.sdoc.models.inline_link import InlineLink
Expand Down Expand Up @@ -141,7 +143,7 @@ def render_node_field(
output = self.fragment_writer.write(parts_output)
self.cache[(document_type, node_field, truncated)] = output

return output
return Markup(output)

def render_free_text(self, document_type, free_text):
assert isinstance(free_text, FreeText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

{%- if sdoc_entity.context.title_number_string -%}
{#- add title 'number' part to the accumulator -#}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". " -%}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". "|safe -%}
{%- endif -%}

{%- set title = sdoc_entity.reserved_title if sdoc_entity.is_requirement else sdoc_entity.title -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{%- if sdoc_entity.context.title_number_string -%}
{#- add title 'number' part to the accumulator -#}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". " -%}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". "|safe -%}
{%- endif -%}

{%- set title = sdoc_entity.reserved_title if sdoc_entity.is_requirement else sdoc_entity.title -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{%- if title_number is true -%}
{%- if sdoc_entity.context.title_number_string %}
{#- add title 'number' part to the accumulator -#}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". " -%}
{%- set field_content_ = field_content_ + sdoc_entity.context.title_number_string + ". "|safe -%}
{%- endif -%}
{%- endif -%}

Expand Down

0 comments on commit 6039713

Please sign in to comment.