nodebb-plugin-onekite-discord 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/library.js +28 -13
  2. package/package.json +1 -1
  3. package/plugin.json +1 -1
package/library.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
-
4
-
5
1
  /**
6
- * Discord doesn't support masked links like [text](url) inside embed descriptions.
7
- * To keep links clickable, convert them to plain URLs (Discord auto-linkifies).
2
+ * Normalize links for Discord embeds.
3
+ * Discord does NOT support masked links in embed descriptions.
4
+ * NodeBB may already render links as: texte(url)
5
+ * We always output a plain URL so Discord auto-linkifies it.
8
6
  */
9
7
  function formatDiscordLinks(str) {
10
8
  if (!str || typeof str !== 'string') return str;
@@ -12,20 +10,37 @@ function formatDiscordLinks(str) {
12
10
  const normalizeUrl = (u) => {
13
11
  if (!u) return u;
14
12
  let url = String(u).trim();
15
-
16
- // Strip wrapping <> if present
17
13
  url = url.replace(/^<(.+)>$/, '$1');
18
-
19
- // Fix common "https:/" typo
20
14
  url = url.replace(/^https:\//i, 'https://');
21
15
  url = url.replace(/^http:\//i, 'http://');
22
-
23
- // If it's a bare domain starting with www., add scheme
24
16
  if (/^www\./i.test(url)) url = 'https://' + url;
25
-
26
17
  return url;
27
18
  };
28
19
 
20
+ // HTML <a href>
21
+ str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>.*?<\/a>/gi, (_m, href) => {
22
+ return normalizeUrl(href);
23
+ });
24
+
25
+ // Markdown [text](url)
26
+ str = str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, _text, url) => {
27
+ return normalizeUrl(url);
28
+ });
29
+
30
+ // Already-rendered form: texte(url)
31
+ str = str.replace(/([^\s(]+)\((https?:\/\/[^)]+|www\.[^)]+)\)/g, (_m, _text, url) => {
32
+ return normalizeUrl(url);
33
+ });
34
+
35
+ return str;
36
+ }
37
+
38
+ 'use strict';
39
+
40
+
41
+
42
+ ;
43
+
29
44
  // HTML links -> URL
30
45
  str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>(.*?)<\/a>/gi, (_m, href, _text) => {
31
46
  return normalizeUrl(href);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-onekite-discord",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/plugin.json CHANGED
@@ -31,5 +31,5 @@
31
31
  "acpScripts": [
32
32
  "public/admin.js"
33
33
  ],
34
- "version": "1.0.9"
34
+ "version": "1.0.10"
35
35
  }