From 3a7d3ef1c994ae9eedd56db17a50c5ba5f3df4be Mon Sep 17 00:00:00 2001 From: Mathieu Dulac Date: Wed, 28 Oct 2020 22:34:18 +0100 Subject: [PATCH] =?UTF-8?q?Rendre=20clickable=20les=20liens=20dans=20les?= =?UTF-8?q?=20demandes=20et=20ses=20r=C3=A9ponses=20(#809)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: niladic --- package.json | 1 + typescript/src/anchorme.ts | 18 ++++++++++++++++++ typescript/src/index.ts | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 typescript/src/anchorme.ts diff --git a/package.json b/package.json index 9fe611f24..5ac91e5ef 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "clean": "rimraf public/generated-js" }, "dependencies": { + "anchorme": "2.1.2", "ts-polyfill": "3.8.2" }, "devDependencies": { diff --git a/typescript/src/anchorme.ts b/typescript/src/anchorme.ts new file mode 100644 index 000000000..568a2dd13 --- /dev/null +++ b/typescript/src/anchorme.ts @@ -0,0 +1,18 @@ +import anchorme from "anchorme" +import {Options} from "anchorme/dist/node/types"; + +const options: Partial = { + attributes: { + target: "_blank", + rel: "nofollow noreferrer noopener" + }, +} + +const descriptions: HTMLCollectionOf = document.getElementsByClassName("application__message") as HTMLCollectionOf + +Array.from(descriptions).forEach((description) => { + const content: string | null = description.innerText ? anchorme({input: description.innerText, options}) : null + if (content) { + description.innerHTML = content + } +}); \ No newline at end of file diff --git a/typescript/src/index.ts b/typescript/src/index.ts index 0cf9094e9..ea4ce264e 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -7,5 +7,6 @@ import 'core-js/web/dom-collections'; // Our scripts import "./admin.ts" import "./mdl-extensions.ts" -import "./application-attachment" import "./validateAccount" +import "./application-attachment" +import "./anchorme"