Skip to content

Commit 65cf956

Browse files
committed
correct markdown renderer for news
1 parent ae48c3e commit 65cf956

File tree

4 files changed

+80
-43
lines changed

4 files changed

+80
-43
lines changed

app/page.tsx

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Image from "next/image";
88

99
import { title, subtitle } from "@/components/primitives";
1010
import { newsList, News } from "@/config/news"
11+
import { remark } from 'remark';
12+
import html from 'remark-html';
1113

1214
function 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

8671
export default function Home() {

config/news.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const newsList: News[] = [
1111
},
1212
{
1313
date: "Aug, 2025",
14-
content: "Our paper *RephQA* received the ** Blue Sky Best Paper Award ** at ACM KDD 2025."
14+
content: "Our paper *RephQA* received the *Blue Sky Best Paper Award* at ACM KDD 2025."
1515
},
1616
{
1717
date: "Jul, 2025",

package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
"rehype-pretty-code": "^0.14.0",
4747
"rehype-stringify": "^10.0.1",
4848
"rehype-unwrap-images": "^1.0.0",
49+
"remark": "^15.0.1",
4950
"remark-gfm": "^4.0.0",
51+
"remark-html": "^16.0.1",
5052
"remark-math": "^6.0.0",
5153
"remark-mdx-images": "^3.0.0",
5254
"sharp": "^0.33.5",

0 commit comments

Comments
 (0)