Skip to content

Commit 4593ed8

Browse files
Fix: Markdown formatting for links and bold text
Corrects markdown formatting issues in blog posts, specifically addressing incorrect link and bold text rendering.
1 parent c2aec2b commit 4593ed8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/BlogContent.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ const BlogContent: React.FC<BlogContentProps> = ({ content }) => {
99
// Transform markdown-like content to JSX
1010
const createMarkup = () => {
1111
let html = content
12+
// Bold text formatting
13+
.replace(/\*\*(.*?)\*\*/g, '<strong class="font-bold">$1</strong>')
14+
15+
// Links
16+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" class="text-primary hover:underline" target="_blank" rel="noopener noreferrer">$1</a>')
17+
1218
// Headers
1319
.replace(/^# (.*$)/gm, '<h1 class="blog-heading">$1</h1>')
1420
.replace(/^## (.*$)/gm, '<h2 class="blog-subheading">$1</h2>')
1521
.replace(/^### (.*$)/gm, '<h3 class="text-xl font-semibold mb-3">$1</h3>')
22+
1623
// Paragraphs
17-
.replace(/^(?!<h[1-6]|<ul|<ol|<li|<blockquote|<pre)(.+$)/gm, '<p class="blog-text">$1</p>')
24+
.replace(/^(?!<h[1-6]|<ul|<ol|<li|<blockquote|<pre|<strong)(.+$)/gm, '<p class="blog-text">$1</p>')
25+
1826
// Lists
1927
.replace(/^- (.*)$/gm, '<li class="ml-6 list-disc">$1</li>')
28+
2029
// Line breaks
2130
.replace(/\n\n/g, '<br />')
31+
2232
// Convert list items into proper lists
2333
.replace(/<li class="ml-6 list-disc">(.*?)<\/li>(?:\n<li class="ml-6 list-disc">(.*?)<\/li>)+/gs,
2434
match => `<ul class="mb-6">${match}</ul>`);

0 commit comments

Comments
 (0)