Skip to content

Commit f508bdd

Browse files
authored
FEATURE: Respect external_links_in_new_tab in category banner descriptions (#114)
* FEATURE: Respect `external_links_in_new_tab` in category banner descriptions Previously, external links inside a category banner description ignored the user's "Open most external links in a new tab" preference because the banner renders outside the topic root and so escaped the post-level click tracker. This adds a guarded click handler on the description that reuses `shouldOpenInNewTab` and `wantsNewWindow`, opening external links in a new tab when the option is enabled while leaving `mailto:`, modifier-clicks, and pre-existing `target="_blank"` links to the browser. * DEV: pr feedback * DEV: no need to test helpers
1 parent 751f0de commit f508bdd

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎javascripts/discourse/components/category-banner.gjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";
66
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
77
import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
88
import { service } from "@ember/service";
9-
import { htmlSafe } from "@ember/template";
9+
import { trustHTML } from "@ember/template";
1010
import CategoryLogo from "discourse/components/category-logo";
11+
import HtmlWithLinks from "discourse/components/html-with-links";
1112
import PluginOutlet from "discourse/components/plugin-outlet";
1213
import { categoryLinkHTML } from "discourse/helpers/category-link";
1314
import icon from "discourse/helpers/d-icon";
@@ -45,7 +46,7 @@ export default class DiscourseCategoryBanners extends Component {
4546
}
4647

4748
get safeStyle() {
48-
return htmlSafe(
49+
return trustHTML(
4950
`--category-banner-background: #${this.category.color}; --category-banner-color: #${this.category.text_color};`
5051
);
5152
}
@@ -211,7 +212,9 @@ export default class DiscourseCategoryBanners extends Component {
211212
this.category.description
212213
}}
213214
>
214-
{{htmlSafe this.category.description}}
215+
<HtmlWithLinks>
216+
{{trustHTML this.category.description}}
217+
</HtmlWithLinks>
215218
<PluginOutlet
216219
@name="category-banners-after-description"
217220
@outletArgs={{lazyHash category=this.category}}

0 commit comments

Comments
 (0)