nodebb-plugin-onekite-discord 1.0.9 → 1.0.11

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 +13 -15
  2. package/package.json +1 -1
  3. package/plugin.json +1 -1
package/library.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
-
4
-
5
3
  /**
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).
4
+ * Normalize links for Discord embeds.
5
+ * Discord does NOT support masked links in embed descriptions.
6
+ * NodeBB may already render links as: texte(url)
7
+ * We always output a plain URL so Discord auto-linkifies it.
8
8
  */
9
9
  function formatDiscordLinks(str) {
10
10
  if (!str || typeof str !== 'string') return str;
@@ -12,30 +12,28 @@ function formatDiscordLinks(str) {
12
12
  const normalizeUrl = (u) => {
13
13
  if (!u) return u;
14
14
  let url = String(u).trim();
15
-
16
- // Strip wrapping <> if present
17
15
  url = url.replace(/^<(.+)>$/, '$1');
18
-
19
- // Fix common "https:/" typo
20
16
  url = url.replace(/^https:\//i, 'https://');
21
17
  url = url.replace(/^http:\//i, 'http://');
22
-
23
- // If it's a bare domain starting with www., add scheme
24
18
  if (/^www\./i.test(url)) url = 'https://' + url;
25
-
26
19
  return url;
27
20
  };
28
21
 
29
- // HTML links -> URL
30
- str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>(.*?)<\/a>/gi, (_m, href, _text) => {
22
+ // HTML <a href="...">...</a> -> URL
23
+ str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>.*?<\/a>/gi, (_m, href) => {
31
24
  return normalizeUrl(href);
32
25
  });
33
26
 
34
- // Markdown links [text](url) -> URL
27
+ // Markdown [text](url) -> URL
35
28
  str = str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, _text, url) => {
36
29
  return normalizeUrl(url);
37
30
  });
38
31
 
32
+ // Already-rendered form: texte(url)
33
+ str = str.replace(/([^\s(]+)\((https?:\/\/[^)]+|www\.[^)]+)\)/g, (_m, _text, url) => {
34
+ return normalizeUrl(url);
35
+ });
36
+
39
37
  return str;
40
38
  }
41
39
 
@@ -303,4 +301,4 @@ Plugin.onTopicReply = async (data) => {
303
301
  await sendDiscord(settings.webhookUrl, { content: built.content, embeds: [built.embed] });
304
302
  };
305
303
 
306
- module.exports = Plugin;
304
+ module.exports = Plugin;
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.11",
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.11"
35
35
  }