diff --git a/src/templates.rs b/src/templates.rs index 96866b8..fb122b2 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -297,6 +297,7 @@ pub async fn middleware( .first() .expect("Expected at least one language to be present due to default") .to_string(); + // Return Value because this value is optional. translations.get_item(&Value::from(selected_language)) }); // Render a fluent message. @@ -363,7 +364,7 @@ pub async fn middleware( let mut html = String::new(); pulldown_cmark::html::push_html(&mut html, parser); - Ok(html) + Ok(Value::from_safe_string(html)) }, ); environment.add_function("ansi_to_html", |ansi_string: &str| { @@ -387,6 +388,19 @@ pub async fn middleware( }) .unwrap_or(().into()); environment.add_function("uuid", || Uuid::new_v4().to_string()); + environment.add_filter("md", |value: Value| { + if value.is_none() || value.is_undefined() { + return value; + } + if let Some(string) = value.as_str() { + let parser = pulldown_cmark::Parser::new(string); + let mut html = String::new(); + pulldown_cmark::html::push_html(&mut html, parser); + Value::from_safe_string(html) + } else { + Value::from(()) + } + }); environment.add_filter("querystring", querystring); environment.add_filter("mapinsert", mapinsert); environment.add_filter("mapremove", mapremove); diff --git a/src/templates/forecast.html b/src/templates/forecast.html index 78bfe52..94e1ab0 100644 --- a/src/templates/forecast.html +++ b/src/templates/forecast.html @@ -157,10 +157,10 @@

{{ fl("problem-type-" ~ problem.kind) }} -

- {{ fl("problem-type-" ~ problem.kind ~ "-about") }} - {{ translated_string(problem.description) }} -

+
+ {{ fl("problem-type-" ~ problem.kind ~ "-about") }} +
+
{{ translated_string(problem.description) | md }}
@@ -169,7 +169,9 @@

{{ fl("problem-type-" ~ problem.kind) }}

- +
{{ fl("distribution-heading") }}{{ fl("distribution-" ~ problem.distribution ~ "-about") }} + {{ fl("distribution-" ~ problem.distribution ~ "-about") }} +
@@ -207,15 +209,15 @@

{{ fl("problem-type-" ~ problem.kind) }} {{ fl("recent-relevant-observations-heading") }}

-

- {{ translated_string(recent_observations) }} -

+
+ {{ translated_string(recent_observations) | md }} +

{{ fl("weather-forecast-heading") }}

-

- {{ translated_string(weather_forecast) }} -

+
+ {{ translated_string(weather_forecast) | md }} +
diff --git a/src/templates/index.html b/src/templates/index.html index a78e24c..0ffa490 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -63,9 +63,7 @@

{{ page_title }}

{{ fl("disclaimer-message") }}

- {% autoescape false %} - {{ fl_md("see-facebook-page-message", {"url": "https://www.facebook.com/groups/830534093958221"}, { "use_isolating": false} ) }} - {% endautoescape %} + {{ fl_md("see-facebook-page-message", {"url": "https://www.facebook.com/groups/830534093958221"}, { "use_isolating": false} ) }}

@@ -78,9 +76,7 @@

{{ fl("forecast-archive-heading") }}

Errors Reading Forecast Files

{% for error in errors %}

Error {{ loop.index }}

- {% autoescape false %} -
{{ ansi_to_html(error) }}
- {% endautoescape %} +
{{ ansi_to_html(error) }}
{% endfor %} {% endif %} diff --git a/src/templates/macros/forecast_intro.html b/src/templates/macros/forecast_intro.html index 4a82303..dee1538 100644 --- a/src/templates/macros/forecast_intro.html +++ b/src/templates/macros/forecast_intro.html @@ -9,24 +9,12 @@

{{ fl("avalanche-hazard-" ~ overall_hazard ~ "-likelihood") }} {{ fl("avalanche-hazard-" ~ overall_hazard ~ "-size-distribution") }}

-

{{ translated_string(description) }}

+
{{ translated_string(description) | md }}
-

- {% autoescape false %} - {{ fl_md("forecast-issued-at", {'time': formatted_time}) }} - {% endautoescape %} -

-

- {% autoescape false %} - {{ fl_md("forecast-valid-until", {'time': formatted_valid_until}) }} - {% endautoescape %} -

-

- {% autoescape false %} - {{ fl_md("forecast-forecaster", {'name': forecaster_name}) }} - {% endautoescape %} -

+

{{ fl_md("forecast-issued-at", {'time': formatted_time}) }}

+

{{ fl_md("forecast-valid-until", {'time': formatted_valid_until}) }}

+

{{ fl_md("forecast-forecaster", {'name': forecaster_name}) }}

{% endmacro %}