community/templates/util.jinja2
kez d67589fc90 Translate slideshow title slides
Context: #251 and !219

Title slides are rendered in the slideshow template, not the slide flowblock
2022-07-26 09:41:08 -07:00

21 lines
907 B
Django/Jinja

{# lektor-i18n-plugin has an edgecase where flowblock markdown isn't properly
translated <https://gitlab.torproject.org/tpo/web/community/-/issues/251#note_2819508>.
any markdown fields in a flowblock need to have a type of `text` and be
rendered with this macro, or they won't be translated.
this macro splits by line, translates all non-whitespace lines, and rejoins.
the `lines.append(...)` method returns `None` so we have to add `or ''` to
avoid rendering the literal text "None" on the page. #}
{# HACK: this is an awful hack and needs to be patched in lektor-i18n-plugin #}
{%- macro render_markdown(md_str) %}
{%- set lines = [] %}
{%- for line in md_str.split('\n') %}
{%- if line.strip() != '' %}
{{- lines.append(_(line)) or '' }}
{%- else %}
{{- lines.append(line) or '' }}
{%- endif %}
{%- endfor %}
{{- md(lines|join('\n')) }}
{% endmacro %}