1
+ import { marked , Tokens } from "marked" ;
1
2
2
3
3
4
const translationModule = TranslateModule . forRoot ( {
@@ -55,7 +56,21 @@ import {provideRouter} from "@angular/router";
55
56
56
57
57
58
import { ApplicationRef } from '@angular/core' ;
58
- import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' ;
59
+ const renderer = new marked . Renderer ( ) ;
60
+ renderer . link = function ( token : Tokens . Link ) : string {
61
+ const { href, title, text } = token ;
62
+ const isImage = text . startsWith ( ' ;
63
+ if ( isImage ) {
64
+ const match = text . match ( / ! \[ ( .* ?) \] \( ( .* ?) \) / ) ;
65
+ if ( match ) {
66
+ const alt = match [ 1 ] ;
67
+ const src = match [ 2 ] ;
68
+ return `<a target="_blank" href="${ href } "><img src="${ src } " alt="${ alt } " /></a>` ;
69
+ }
70
+ }
71
+ return `<a target="_blank" href="${ href } ">${ text } </a>` ;
72
+ } ;
73
+
59
74
60
75
bootstrapApplication ( AppComponent , {
61
76
providers : [
@@ -65,26 +80,7 @@ bootstrapApplication(AppComponent, {
65
80
provide : MARKED_OPTIONS ,
66
81
useValue : {
67
82
breaks : true ,
68
- renderer : {
69
- link ( { href, title, text, tokens } : { href : string ; title ?: string ; text : string ; tokens ?: any [ ] } ) : string {
70
- // Check if the text contains an image tag (Markdown image syntax is wrapped in ``)
71
- const isImage = text . startsWith ( ' ;
72
-
73
- if ( isImage ) {
74
- // Extract the image Markdown (e.g., )
75
- const match = text . match ( / ! \[ ( .* ?) \] \( ( .* ?) \) / ) ; // Regex to parse image Markdown
76
- if ( match ) {
77
- const alt = match [ 1 ] ; // Alt text
78
- const src = match [ 2 ] ; // Image URL
79
- // Render clickable image
80
- return `<a target="_blank" href="${ href } "><img src="${ src } " alt="${ alt } " /></a>` ;
81
- }
82
- }
83
-
84
- // Fallback to standard link rendering for non-image links
85
- return `<a target="_blank" href="${ href } ">${ text } </a>` ;
86
- } ,
87
- } ,
83
+ renderer : renderer ,
88
84
}
89
85
}
90
86
} ) , NgxFlowModule , NgOptimizedImage ) ,
0 commit comments