Skip to content

Commit 38dbde4

Browse files
committed
fix #600
1 parent ce1b59f commit 38dbde4

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- 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.
1818
- **divider component**: Add new properties to the divider component: `link`, `bold`, `italics`, `underline`, `size`.
1919
- **form component**: fix slight misalignment and sizing issues of checkboxes and radio buttons.
20+
- **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.
2021

2122
## 0.28.0 (2024-08-31)
2223
- Chart component: fix the labels of pie charts displaying too many decimal places.

sqlpage/templates/table.handlebars

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{#if (not (starts_with @key '_sqlpage_'))}}
2020
<th class="
2121
{{~@key~}}
22-
{{~#if (array_contains ../../align_right @key)}} text-end {{/if~}}
22+
{{~#if (array_contains_case_insensitive ../../align_right @key)}} text-end {{/if~}}
2323
">
2424
{{~#if ../../sort~}}
2525
<button class="table-sort sort d-inline" data-sort="{{@key}}">{{@key}}</button>
@@ -39,13 +39,13 @@
3939
{{~#if (not (starts_with @key '_sqlpage_'))~}}
4040
<td class="
4141
{{~@key~}}
42-
{{~#if (array_contains ../../align_right @key)
42+
{{~#if (array_contains_case_insensitive ../../align_right @key)
4343
}} text-end {{
4444
/if}} align-middle">
45-
{{~#if (array_contains ../../markdown @key)~}}
45+
{{~#if (array_contains_case_insensitive ../../markdown @key)~}}
4646
{{{markdown this}}}
4747
{{~else~}}
48-
{{~#if (array_contains ../../icon @key)~}}
48+
{{~#if (array_contains_case_insensitive ../../icon @key)~}}
4949
{{~icon_img this~}}
5050
{{~else~}}
5151
{{this}}

src/template_helpers.rs

+16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) {
4141
});
4242
h.register_helper("array_contains", Box::new(array_contains));
4343

44+
// 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.
45+
handlebars_helper!(array_contains_case_insensitive: |array: Json, element: Json| {
46+
match array {
47+
JsonValue::Array(arr) => arr.iter().any(|v| json_eq_case_insensitive(v, element)),
48+
other => json_eq_case_insensitive(other, element),
49+
}
50+
});
51+
h.register_helper("array_contains_case_insensitive", Box::new(array_contains_case_insensitive));
52+
4453
// static_path helper: generate a path to a static file. Replaces sqpage.js by sqlpage.<hash>.js
4554
register_helper(h, "static_path", StaticPathHelper(site_prefix.clone()));
4655
register_helper(h, "app_config", AppConfigHelper(config.clone()));
@@ -55,6 +64,13 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) {
5564
register_helper(h, "csv_escape", csv_escape_helper as HH);
5665
}
5766

67+
fn json_eq_case_insensitive(a: &JsonValue, b: &JsonValue) -> bool {
68+
match (a, b) {
69+
(JsonValue::String(a), JsonValue::String(b)) => a.eq_ignore_ascii_case(b),
70+
_ => a == b,
71+
}
72+
}
73+
5874
fn stringify_helper(v: &JsonValue) -> JsonValue {
5975
v.to_string().into()
6076
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- https://github.com/lovasoa/SQLpage/discussions/600
2+
select 'table' as component, 'Link' AS markdown; -- uppercase Link
3+
select '[It works !](https://example.com)
4+
5+
[comment]: <> (This is a comment. If this is visible, there is an error in markdown rendering)' as link; -- lowercase "link".
6+
-- If the markdown is not rendered, the page will contain the string "error" and trigger a test failure.

0 commit comments

Comments
 (0)