From 6d6b44bd995ac90f6514740c70df41e38b739866 Mon Sep 17 00:00:00 2001 From: mdulac Date: Wed, 28 Oct 2020 20:00:26 +0100 Subject: [PATCH] Use anchorme to make links clickable in application description and answers --- 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 01da126f1..b44489004 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -5,4 +5,5 @@ import 'ts-polyfill/lib/es2015-core'; // Our scripts import "./admin.ts" import "./mdl-extensions.ts" -import "./validateAccount" \ No newline at end of file +import "./validateAccount" +import "./anchorme" \ No newline at end of file