@skalfa/skalfa-component 1.0.36 → 1.0.37
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.
package/dist/index.js
CHANGED
|
@@ -176,6 +176,7 @@ exports.TypographyTipsComponent = require("./typography/TypographyTips.component
|
|
|
176
176
|
|
|
177
177
|
// Static export for ./wrap/ContentWrapper.component
|
|
178
178
|
exports.COLOR_MAP = require("./wrap/ContentWrapper.component").COLOR_MAP;
|
|
179
|
+
exports.formatLinkUrl = require("./wrap/ContentWrapper.component").formatLinkUrl;
|
|
179
180
|
exports.parseInlineFormats = require("./wrap/ContentWrapper.component").parseInlineFormats;
|
|
180
181
|
exports.parseContentToHtml = require("./wrap/ContentWrapper.component").parseContentToHtml;
|
|
181
182
|
exports.parseHtmlToContent = require("./wrap/ContentWrapper.component").parseHtmlToContent;
|
|
@@ -7,6 +7,7 @@ export declare const COLOR_MAP: Record<string, {
|
|
|
7
7
|
tw: string;
|
|
8
8
|
css: string;
|
|
9
9
|
}>;
|
|
10
|
+
export declare function formatLinkUrl(url: string): string;
|
|
10
11
|
export declare function parseInlineFormats(text: string): string;
|
|
11
12
|
export declare function parseContentToHtml(content: string): string;
|
|
12
13
|
export declare function parseHtmlToContent(html: string): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.COLOR_MAP = void 0;
|
|
4
|
+
exports.formatLinkUrl = formatLinkUrl;
|
|
4
5
|
exports.parseInlineFormats = parseInlineFormats;
|
|
5
6
|
exports.parseContentToHtml = parseContentToHtml;
|
|
6
7
|
exports.parseHtmlToContent = parseHtmlToContent;
|
|
@@ -16,6 +17,15 @@ exports.COLOR_MAP = {
|
|
|
16
17
|
warning: { label: "Warning", tw: "text-warning", css: "var(--color-warning, #f59e0b)" },
|
|
17
18
|
danger: { label: "Danger", tw: "text-danger", css: "var(--color-danger, #ef4444)" },
|
|
18
19
|
};
|
|
20
|
+
function formatLinkUrl(url) {
|
|
21
|
+
if (!url)
|
|
22
|
+
return "";
|
|
23
|
+
const hasProtocol = /^(https?:\/\/|\/\/|\/|#|mailto:|tel:|javascript:)/i.test(url);
|
|
24
|
+
if (hasProtocol) {
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
return `https://${url}`;
|
|
28
|
+
}
|
|
19
29
|
function parseInlineFormats(text) {
|
|
20
30
|
if (!text)
|
|
21
31
|
return "";
|
|
@@ -29,7 +39,8 @@ function parseInlineFormats(text) {
|
|
|
29
39
|
return `<span style="font-size:${size}px" data-size="${size}">${content}</span>`;
|
|
30
40
|
});
|
|
31
41
|
result = result.replace(/\[link:(.*?)\](.*?)\[link\]/g, (_, url, content) => {
|
|
32
|
-
|
|
42
|
+
const formattedUrl = formatLinkUrl(url);
|
|
43
|
+
return `<a href="${formattedUrl}" class="text-primary underline" data-link="${formattedUrl}" target="_blank" rel="noopener noreferrer">${content}</a>`;
|
|
33
44
|
});
|
|
34
45
|
result = result.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>");
|
|
35
46
|
result = result.replace(/\/\/(.*?)\/\//g, "<em>$1</em>");
|
package/package.json
CHANGED
|
@@ -15,6 +15,15 @@ export const COLOR_MAP: Record<string, { label: string; tw: string; css: string
|
|
|
15
15
|
danger: { label: "Danger", tw: "text-danger", css: "var(--color-danger, #ef4444)" },
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
export function formatLinkUrl(url: string): string {
|
|
19
|
+
if (!url) return "";
|
|
20
|
+
const hasProtocol = /^(https?:\/\/|\/\/|\/|#|mailto:|tel:|javascript:)/i.test(url);
|
|
21
|
+
if (hasProtocol) {
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
return `https://${url}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export function parseInlineFormats(text: string): string {
|
|
19
28
|
if (!text) return "";
|
|
20
29
|
let result = text;
|
|
@@ -30,7 +39,8 @@ export function parseInlineFormats(text: string): string {
|
|
|
30
39
|
});
|
|
31
40
|
|
|
32
41
|
result = result.replace(/\[link:(.*?)\](.*?)\[link\]/g, (_, url, content) => {
|
|
33
|
-
|
|
42
|
+
const formattedUrl = formatLinkUrl(url);
|
|
43
|
+
return `<a href="${formattedUrl}" class="text-primary underline" data-link="${formattedUrl}" target="_blank" rel="noopener noreferrer">${content}</a>`;
|
|
34
44
|
});
|
|
35
45
|
|
|
36
46
|
result = result.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>");
|