Skip to content

Commit bba6bbf

Browse files
committed
add line breaks in content
1 parent d8648e2 commit bba6bbf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/CourseDetail.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@ import courses from './courseData'; // Ensure the path is correct
44

55
function CourseDetail() {
66
const { courseName } = useParams();
7-
8-
// Convert the URL back to the sanitized course key
9-
const courseKey = courseName.toLowerCase(); // Ensures proper formatting
10-
7+
const courseKey = courseName.toLowerCase(); // Ensure proper formatting
118
const course = courses[courseKey]; // Lookup using the sanitized course key
129

1310
if (!course) {
1411
return <h2 className="text-center">Course not found</h2>;
1512
}
1613

14+
// Function to convert newlines to <br />
15+
const formatContent = (content) => {
16+
return content.split('\n').map((line, index) => (
17+
<span key={index}>
18+
{line}
19+
<br />
20+
</span>
21+
));
22+
};
23+
1724
return (
1825
<div className="container mt-5">
1926
<h2>{course.title}</h2>
2027
<img src={course.image} alt={course.title} className="img-fluid" />
2128
<p>{course.description}</p>
2229
<h4>Course Content:</h4>
23-
<p>{course.content}</p>
30+
<p>{formatContent(course.content)}</p>
2431
</div>
2532
);
2633
}

0 commit comments

Comments
 (0)