@@ -8,6 +8,8 @@ import Image from "next/image";
88
99import { title , subtitle } from "@/components/primitives" ;
1010import { newsList , News } from "@/config/news"
11+ import { remark } from 'remark' ;
12+ import html from 'remark-html' ;
1113
1214function ResearchDirection ( { title, image } : { title : string ; image : string } ) {
1315 return (
@@ -35,52 +37,35 @@ function ResearchDirection({ title, image }: { title: string; image: string }) {
3537 ) ;
3638}
3739
38-
39- function replaceMarkdownLinks ( text : string ) : React . ReactNode [ ] {
40- const parts : React . ReactNode [ ] = [ ] ;
41- const regex = / \[ ( [ ^ \] ] + ) \] \( ( [ ^ ) ] + ) \) / g;
42- let lastIndex = 0 ;
43- let match ;
44-
45- while ( ( match = regex . exec ( text ) ) !== null ) {
46- const [ fullMatch , title , url ] = match ;
47- const matchStart = match . index ;
48-
49- // Add text before the link
50- if ( lastIndex < matchStart ) {
51- parts . push ( text . slice ( lastIndex , matchStart ) ) ;
52- }
53-
54- // Add JSX Link component
55- parts . push (
56- < Link key = { parts . length } href = { url } >
57- { title }
58- </ Link >
40+ function ExpandNews ( news : News , index : number ) {
41+ // Custom renderer for <a> tags
42+ function renderHtmlWithCustomLinks ( htmlString : string ) {
43+ return (
44+ < span
45+ dangerouslySetInnerHTML = { {
46+ __html : htmlString . replace (
47+ / < a / g,
48+ '<a style="color:#0070f3;text-decoration;" '
49+ ) ,
50+ } }
51+ />
5952 ) ;
60-
61- lastIndex = matchStart + fullMatch . length ;
62- }
63-
64- // Add remaining text after the last match
65- if ( lastIndex < text . length ) {
66- parts . push ( text . slice ( lastIndex ) ) ;
6753 }
6854
69- return parts ;
70- }
71-
55+ const htmlContent = remark ( ) . use ( html ) . processSync ( news . content ) . toString ( ) ;
7256
73- function ExpandNews ( news : News , index : number ) {
74- return ( < li key = { index } >
75- < div style = { { display : 'flex' , alignItems : 'flex-start' } } >
76- < span style = { { width : '100px' , flexShrink : 0 } } >
77- < em > { news . date } </ em >
78- </ span >
79- < span style = { { marginLeft : '1em' } } >
80- { replaceMarkdownLinks ( news . content ) }
81- </ span >
82- </ div >
83- </ li > )
57+ return (
58+ < li key = { index } >
59+ < div style = { { display : 'flex' , alignItems : 'flex-start' } } >
60+ < span style = { { width : '100px' , flexShrink : 0 } } >
61+ < em > { news . date } </ em >
62+ </ span >
63+ < span style = { { marginLeft : '1em' } } >
64+ { renderHtmlWithCustomLinks ( htmlContent ) }
65+ </ span >
66+ </ div >
67+ </ li >
68+ ) ;
8469}
8570
8671export default function Home ( ) {
0 commit comments