diff --git a/src/components/templates/classic/sections/EducationSection.tsx b/src/components/templates/classic/sections/EducationSection.tsx index b750788..563431a 100644 --- a/src/components/templates/classic/sections/EducationSection.tsx +++ b/src/components/templates/classic/sections/EducationSection.tsx @@ -3,7 +3,7 @@ import { Education, GlobalSettings } from "@/types/resume"; import SectionTitle from "./SectionTitle"; import SectionWrapper from "../../shared/SectionWrapper"; import { useLocale } from "@/i18n/compat/client"; -import { normalizeRichTextContent } from "@/lib/richText"; +import { hasMeaningfulRichTextContent, normalizeRichTextContent } from "@/lib/richText"; import { formatDateString } from "@/lib/utils"; interface EducationSectionProps { @@ -25,7 +25,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {visibleEducation?.map((edu) => ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( /i; const EMPTY_PARAGRAPH_REGEX = /

(?:\s| |)*<\/p>/gi; +const HTML_BREAK_REGEX = //gi; +const HTML_ANY_TAG_REGEX = /<\/?[^>]+>/g; +const INVISIBLE_WHITESPACE_REGEX = /[\s\u200B-\u200D\uFEFF]/g; const escapeHtml = (text: string) => text @@ -23,3 +26,20 @@ export const normalizeRichTextContent = (content?: string) => { return normalized.replace(EMPTY_PARAGRAPH_REGEX, "


"); }; + +export const hasMeaningfulRichTextContent = (content?: string) => { + if (!content) return false; + + if (!HTML_TAG_REGEX.test(content)) { + return content.replace(INVISIBLE_WHITESPACE_REGEX, "").length > 0; + } + + const plainText = content + .replace(EMPTY_PARAGRAPH_REGEX, "") + .replace(HTML_BREAK_REGEX, "") + .replace(/ /gi, " ") + .replace(HTML_ANY_TAG_REGEX, "") + .replace(INVISIBLE_WHITESPACE_REGEX, ""); + + return plainText.length > 0; +};