valtech-components 2.0.288 → 2.0.289
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/README.md +20 -20
- package/esm2022/lib/components/atoms/text/text.component.mjs +3 -3
- package/esm2022/lib/examples/link-processing-example.component.mjs +51 -1
- package/esm2022/lib/services/link-processor.service.mjs +75 -30
- package/fesm2022/valtech-components.mjs +126 -31
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/examples/link-processing-example.component.d.ts +2 -0
- package/lib/services/link-processor.service.d.ts +17 -11
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@ export declare class LinkProcessingExampleComponent {
|
|
|
17
17
|
customLinksProps: TextMetadata;
|
|
18
18
|
mixedLinksProps: TextMetadata;
|
|
19
19
|
sameTabLinksProps: TextMetadata;
|
|
20
|
+
markdownLinksProps: TextMetadata;
|
|
21
|
+
mixedFormatsProps: TextMetadata;
|
|
20
22
|
static ɵfac: i0.ɵɵFactoryDeclaration<LinkProcessingExampleComponent, never>;
|
|
21
23
|
static ɵcmp: i0.ɵɵComponentDeclaration<LinkProcessingExampleComponent, "val-link-processing-example", never, {}, {}, never, never, true, never>;
|
|
22
24
|
}
|
|
@@ -11,19 +11,21 @@ export interface LinkProcessorConfig {
|
|
|
11
11
|
externalLinkClass?: string;
|
|
12
12
|
/** Custom CSS classes for internal links */
|
|
13
13
|
internalLinkClass?: string;
|
|
14
|
+
/** Whether to process Markdown-style links [text](url) (default: true) */
|
|
15
|
+
processMarkdownLinks?: boolean;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* LinkProcessorService - Service for processing text content to convert URLs and internal routes into clickable links.
|
|
17
19
|
*
|
|
18
|
-
* This service automatically detects external URLs (http/https)
|
|
19
|
-
* and converts them into HTML anchor elements with appropriate attributes.
|
|
20
|
+
* This service automatically detects external URLs (http/https), internal routes (starting with /),
|
|
21
|
+
* and Markdown-style links [text](url) and converts them into HTML anchor elements with appropriate attributes.
|
|
20
22
|
*
|
|
21
23
|
* @example Basic usage:
|
|
22
24
|
* ```typescript
|
|
23
25
|
* constructor(private linkProcessor: LinkProcessorService) {}
|
|
24
26
|
*
|
|
25
27
|
* processText() {
|
|
26
|
-
* const text = 'Visit https://example.com
|
|
28
|
+
* const text = 'Visit https://example.com, go to /profile, or [check docs](https://docs.example.com)';
|
|
27
29
|
* const processed = this.linkProcessor.processLinks(text);
|
|
28
30
|
* // Returns SafeHtml with clickable links
|
|
29
31
|
* }
|
|
@@ -33,10 +35,11 @@ export declare class LinkProcessorService {
|
|
|
33
35
|
private sanitizer;
|
|
34
36
|
private readonly urlRegex;
|
|
35
37
|
private readonly internalRouteRegex;
|
|
38
|
+
private readonly markdownLinkRegex;
|
|
36
39
|
constructor(sanitizer: DomSanitizer);
|
|
37
40
|
/**
|
|
38
41
|
* Procesa texto para convertir enlaces en elementos <a> clickeables.
|
|
39
|
-
* Detecta automáticamente URLs externas
|
|
42
|
+
* Detecta automáticamente URLs externas, rutas internas y enlaces estilo Markdown.
|
|
40
43
|
*
|
|
41
44
|
* @param text - Texto a procesar
|
|
42
45
|
* @param config - Configuración del procesamiento
|
|
@@ -45,10 +48,11 @@ export declare class LinkProcessorService {
|
|
|
45
48
|
* @example
|
|
46
49
|
* ```typescript
|
|
47
50
|
* const result = this.linkProcessor.processLinks(
|
|
48
|
-
* 'Visit https://example.com
|
|
51
|
+
* 'Visit https://example.com, go to /profile, or [check docs](https://docs.example.com)',
|
|
49
52
|
* {
|
|
50
53
|
* openExternalInNewTab: true,
|
|
51
54
|
* openInternalInNewTab: false,
|
|
55
|
+
* processMarkdownLinks: true,
|
|
52
56
|
* linkClass: 'custom-link'
|
|
53
57
|
* }
|
|
54
58
|
* );
|
|
@@ -56,14 +60,14 @@ export declare class LinkProcessorService {
|
|
|
56
60
|
*/
|
|
57
61
|
processLinks(text: string, config?: LinkProcessorConfig): SafeHtml | string;
|
|
58
62
|
/**
|
|
59
|
-
* Detecta si un texto contiene enlaces (URLs o
|
|
63
|
+
* Detecta si un texto contiene enlaces (URLs, rutas internas o enlaces Markdown).
|
|
60
64
|
*
|
|
61
65
|
* @param text - Texto a analizar
|
|
62
66
|
* @returns true si contiene enlaces
|
|
63
67
|
*
|
|
64
68
|
* @example
|
|
65
69
|
* ```typescript
|
|
66
|
-
* const hasLinks = this.linkProcessor.hasLinks('Visit https://example.com');
|
|
70
|
+
* const hasLinks = this.linkProcessor.hasLinks('Visit https://example.com or [docs](https://docs.com)');
|
|
67
71
|
* // Returns: true
|
|
68
72
|
* ```
|
|
69
73
|
*/
|
|
@@ -72,20 +76,22 @@ export declare class LinkProcessorService {
|
|
|
72
76
|
* Extrae todos los enlaces de un texto.
|
|
73
77
|
*
|
|
74
78
|
* @param text - Texto a analizar
|
|
75
|
-
* @returns Array de enlaces encontrados con su tipo
|
|
79
|
+
* @returns Array de enlaces encontrados con su tipo y texto (si es Markdown)
|
|
76
80
|
*
|
|
77
81
|
* @example
|
|
78
82
|
* ```typescript
|
|
79
|
-
* const links = this.linkProcessor.extractLinks('Visit https://example.com or
|
|
83
|
+
* const links = this.linkProcessor.extractLinks('Visit https://example.com, /profile, or [docs](https://docs.com)');
|
|
80
84
|
* // Returns: [
|
|
81
|
-
* // { url: 'https://example.com', type: 'external' },
|
|
82
|
-
* // { url: '/profile', type: 'internal' }
|
|
85
|
+
* // { url: 'https://example.com', type: 'external', text: 'https://example.com' },
|
|
86
|
+
* // { url: '/profile', type: 'internal', text: '/profile' },
|
|
87
|
+
* // { url: 'https://docs.com', type: 'external', text: 'docs' }
|
|
83
88
|
* // ]
|
|
84
89
|
* ```
|
|
85
90
|
*/
|
|
86
91
|
extractLinks(text: string): Array<{
|
|
87
92
|
url: string;
|
|
88
93
|
type: 'external' | 'internal';
|
|
94
|
+
text: string;
|
|
89
95
|
}>;
|
|
90
96
|
static ɵfac: i0.ɵɵFactoryDeclaration<LinkProcessorService, never>;
|
|
91
97
|
static ɵprov: i0.ɵɵInjectableDeclaration<LinkProcessorService>;
|