diff --git a/cypress/e2e/e2e/solid-display.cy.ts b/cypress/e2e/e2e/solid-display.cy.ts index 4183a038f35a939399497a3eb5c55efd87ad618c..3874cc66cd67ba13b22677b49f02d3c3a7bf4e66 100644 --- a/cypress/e2e/e2e/solid-display.cy.ts +++ b/cypress/e2e/e2e/solid-display.cy.ts @@ -355,4 +355,21 @@ describe('solid-display', function () { .find('solid-display-value-label') .should('have.class', 'solid-display-value-label emailClass'); }); + + it('should render bold text without extra spaces', () => { + cy.get( + 'solid-display#display-bold-no-whitespaces solid-display-value-markdown-label', + ) + .find('p') + .as('text'); + + cy.get('@text').should( + 'contain.text', + "La Société d'Economie Mixte Energies Renouvelables 36", + ); + cy.get('@text').should( + 'contain.html', + "<strong>La Société d'Economie Mixte Energies Renouvelables 36</strong>", + ); + }); }); diff --git a/examples/data/markdown-text.jsonld b/examples/data/markdown-text.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..d04d0d61faa8e5fdd2114528f1e2e9a3add15841 --- /dev/null +++ b/examples/data/markdown-text.jsonld @@ -0,0 +1,19 @@ +{ + "@id": "/examples/data/markdown-text.jsonld", + "creation_date": "2024-11-25T16:06:33.485578Z", + "update_date": "2025-02-19T15:57:17.092848Z", + "citizen_project": { + "@id": "https://api.ep-contributions.startinblox.com/citizenprojects/33/", + "@type": "energiepartagee:citizen_project" + }, + "is_featured": false, + "crowdfunding_url": null, + "general_description": "** La Société d'Economie Mixte Energies Renouvelables 36 **(SEMER)", + "star_initiative_briefing": null, + "stakes_description": null, + "replicability": null, + "additional_informations": null, + "@type": "energiepartagee:communication_profile", + "permissions": ["view"], + "@context": "https://cdn.startinblox.com/owl/context.jsonld" +} diff --git a/examples/e2e/solid-display.html b/examples/e2e/solid-display.html index 7d9f36699aa7a443120edc90a2727d974dd35a01..64a4974ba3d6583979f46f2f30a9baf1999826f5 100644 --- a/examples/e2e/solid-display.html +++ b/examples/e2e/solid-display.html @@ -328,6 +328,15 @@ widget-email="solid-display-value-label" ></solid-display> + <h3>Render bold text without extra spaces</h3> + <solid-display + id="display-bold-no-whitespaces" + data-src="/examples/data/markdown-text.jsonld" + fields="general_description" + label-general_description="Texte en markdown : " + widget-general_description="solid-display-value-markdown-label" + ></solid-display> + <script> const log = document.getElementById('log-event'); document.getElementById('display-event').addEventListener('widgetRendered', (e) => { diff --git a/src/new-widgets/valueTransformationMixins/markdownMixin.ts b/src/new-widgets/valueTransformationMixins/markdownMixin.ts index 7b2382b544277a66c3e6d46ab791bf6f3645b4de..c9299aca1d16115508bfc48049682c1f45abd40b 100644 --- a/src/new-widgets/valueTransformationMixins/markdownMixin.ts +++ b/src/new-widgets/valueTransformationMixins/markdownMixin.ts @@ -31,7 +31,8 @@ const MarkdownMixin = { }, }); - const html = md.render(value); + const cleanedText = value.replace(/\*\*\s*(.*?)\s*\*\*/g, '**$1**'); + const html = md.render(cleanedText); newValue = unsafeHTML(html); }