Skip to content

Commit

Permalink
add line breaks in content
Browse files Browse the repository at this point in the history
  • Loading branch information
devsdenepal committed Sep 21, 2024
1 parent d8648e2 commit bba6bbf
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/components/CourseDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ import courses from './courseData'; // Ensure the path is correct

function CourseDetail() {
const { courseName } = useParams();

// Convert the URL back to the sanitized course key
const courseKey = courseName.toLowerCase(); // Ensures proper formatting

const courseKey = courseName.toLowerCase(); // Ensure proper formatting
const course = courses[courseKey]; // Lookup using the sanitized course key

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

// Function to convert newlines to <br />
const formatContent = (content) => {
return content.split('\n').map((line, index) => (
<span key={index}>
{line}
<br />
</span>
));
};

return (
<div className="container mt-5">
<h2>{course.title}</h2>
<img src={course.image} alt={course.title} className="img-fluid" />
<p>{course.description}</p>
<h4>Course Content:</h4>
<p>{course.content}</p>
<p>{formatContent(course.content)}</p>
</div>
);
}
Expand Down

0 comments on commit bba6bbf

Please sign in to comment.