diff --git a/CHANGELOG.md b/CHANGELOG.md index fe05570c..e7c01cd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Add new properties to the foldable component: `id`, `class`, and `expanded` (to control the state of the foldable item). The old behavior was having the first foldable item initially opened and the others closed. To keep the old behavior, you need to explicitly set `true as expanded` on the first foldable item. - **divider component**: Add new properties to the divider component: `link`, `bold`, `italics`, `underline`, `size`. - **form component**: fix slight misalignment and sizing issues of checkboxes and radio buttons. + - **table component**: fixed a bug where markdown contents of table cells would not be rendered as markdown if the column name contained uppercase letters on Postgres. Column name matching is now case-insensitive, so `'title' as markdown` will work the same as `'Title' as markdown`. In postgres, non-double-quoted identifiers are always folded to lowercase. ## 0.28.0 (2024-08-31) - Chart component: fix the labels of pie charts displaying too many decimal places. diff --git a/sqlpage/templates/table.handlebars b/sqlpage/templates/table.handlebars index 257101ef..7f6efded 100644 --- a/sqlpage/templates/table.handlebars +++ b/sqlpage/templates/table.handlebars @@ -19,7 +19,7 @@ {{#if (not (starts_with @key '_sqlpage_'))}} {{~#if ../../sort~}} @@ -39,13 +39,13 @@ {{~#if (not (starts_with @key '_sqlpage_'))~}} - {{~#if (array_contains ../../markdown @key)~}} + {{~#if (array_contains_case_insensitive ../../markdown @key)~}} {{{markdown this}}} {{~else~}} - {{~#if (array_contains ../../icon @key)~}} + {{~#if (array_contains_case_insensitive ../../icon @key)~}} {{~icon_img this~}} {{~else~}} {{this}} diff --git a/src/template_helpers.rs b/src/template_helpers.rs index e7de3b1e..324f082f 100644 --- a/src/template_helpers.rs +++ b/src/template_helpers.rs @@ -41,6 +41,15 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) { }); h.register_helper("array_contains", Box::new(array_contains)); + // array_contains_case_insensitive: check if an array contains an element case-insensitively. If the first argument is not an array, it is compared to the second argument case-insensitively. + handlebars_helper!(array_contains_case_insensitive: |array: Json, element: Json| { + match array { + JsonValue::Array(arr) => arr.iter().any(|v| json_eq_case_insensitive(v, element)), + other => json_eq_case_insensitive(other, element), + } + }); + h.register_helper("array_contains_case_insensitive", Box::new(array_contains_case_insensitive)); + // static_path helper: generate a path to a static file. Replaces sqpage.js by sqlpage..js register_helper(h, "static_path", StaticPathHelper(site_prefix.clone())); register_helper(h, "app_config", AppConfigHelper(config.clone())); @@ -55,6 +64,13 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) { register_helper(h, "csv_escape", csv_escape_helper as HH); } +fn json_eq_case_insensitive(a: &JsonValue, b: &JsonValue) -> bool { + match (a, b) { + (JsonValue::String(a), JsonValue::String(b)) => a.eq_ignore_ascii_case(b), + _ => a == b, + } +} + fn stringify_helper(v: &JsonValue) -> JsonValue { v.to_string().into() } diff --git a/tests/sql_test_files/it_works_markdown_in_table.sql b/tests/sql_test_files/it_works_markdown_in_table.sql new file mode 100644 index 00000000..8f0f28a8 --- /dev/null +++ b/tests/sql_test_files/it_works_markdown_in_table.sql @@ -0,0 +1,6 @@ +-- https://github.com/lovasoa/SQLpage/discussions/600 +select 'table' as component, 'Link' AS markdown; -- uppercase Link +select '[It works !](https://example.com) + +[comment]: <> (This is a comment. If this is visible, there is an error in markdown rendering)' as link; -- lowercase "link". +-- If the markdown is not rendered, the page will contain the string "error" and trigger a test failure.