Skip to content

Commit d52ddf4

Browse files
Mattia VianelliMattia Vianelli
authored andcommitted
DSC-2668 Updated link rendering to be able to render plain text values for licenses
(cherry picked from commit 49edf6da7211b70030ed3e7be65b53f87deb479f)
1 parent 7a864f8 commit d52ddf4

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div [class]="field.styleValue" [attr.lang]="metadataValue.language">
2+
@if (isLink) {
23
<span class="link-value">
34
<a href="{{link.href}}" target="_blank">{{ link.text }}</a>
45
</span>
6+
} @else {
7+
<span class="plain-text-value">{{ link.text }}</span>
8+
}
59
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/link/link.component.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export class LinkComponent extends RenderingTypeValueModelComponent implements O
3737
*/
3838
link: MetadataLinkValue;
3939

40+
/**
41+
* Flag to determine if the value is a valid URL
42+
*/
43+
isLink = false;
44+
4045
isEmail = false;
4146

4247
constructor(
@@ -51,9 +56,25 @@ export class LinkComponent extends RenderingTypeValueModelComponent implements O
5156
}
5257

5358
ngOnInit(): void {
59+
this.isLink = this.isValidUrl();
5460
this.link = this.getLinkFromValue();
5561
}
5662

63+
/**
64+
* Check if the metadata value is a valid URL
65+
*/
66+
isValidUrl(): boolean {
67+
const value = this.metadataValue.value.trim();
68+
69+
// Comprehensive URL regex that matches:
70+
// - URLs with protocols (http, https, ftp, mailto, etc.)
71+
// - URLs without protocols (www.example.com, example.com)
72+
// - URLs with paths, query strings, and fragments
73+
const urlRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
74+
75+
return urlRegex.test(value);
76+
}
77+
5778
/**
5879
* Get the link value to render
5980
*/

0 commit comments

Comments
 (0)