Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] utilise un nouveau composant pour afficher le markdown (pix-12552) #8947

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admin/app/components/campaigns/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@

{{#if @campaign.customLandingPageText}}
<li>Texte de la page d'accueil :
<MarkdownToHtml @markdown={{@campaign.customLandingPageText}} />
<SafeMarkdownToHtml @markdown={{@campaign.customLandingPageText}} />
</li>
{{/if}}
{{#if @campaign.customResultPageText}}
<li>Texte de la page de fin de parcours :
<MarkdownToHtml @markdown={{@campaign.customResultPageText}} />
<SafeMarkdownToHtml @markdown={{@campaign.customResultPageText}} />
</li>
{{/if}}
{{#if @campaign.customResultPageButtonText}}
Expand Down
3 changes: 3 additions & 0 deletions admin/app/components/safe-markdown-to-html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class={{@class}} ...attributes>
{{this.toHtml @markdown}}
</div>
31 changes: 31 additions & 0 deletions admin/app/components/safe-markdown-to-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { htmlSafe } from '@ember/template';
import Component from '@glimmer/component';
import showdown from 'showdown';
import xss from 'xss';

const xssWhitelist = {
...xss.whiteList,
style: [],
span: ['style'],
th: ['style'],
td: ['style'],
tr: ['style'],
table: ['style'],
a: ['href', 'rel', 'target', 'title'],
};

const showdownOptions = {
openLinksInNewWindow: true,
strikethrough: true,
};

export default class SafeMarkdownToHtml extends Component {
toHtml(markdown) {
const converter = new showdown.Converter(showdownOptions);
const unsafeHtml = converter.makeHtml(markdown);
const html = xss(unsafeHtml, {
whiteList: xssWhitelist,
});
return htmlSafe(html);
}
}
4 changes: 2 additions & 2 deletions admin/app/components/target-profiles/target-profile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
{{#if @model.description}}
<li>
<span class="bold">Description&#x20;:&#x20;</span>
<MarkdownToHtml @markdown={{@model.description}} />
<SafeMarkdownToHtml @markdown={{@model.description}} />
</li>
{{/if}}
{{#if @model.comment}}
<li>
<span class="bold">Commentaire (usage interne)&#x20;:&#x20;</span>
<MarkdownToHtml @markdown={{@model.comment}} />
<SafeMarkdownToHtml @markdown={{@model.comment}} />
</li>
{{/if}}
</ul>
Expand Down
Loading