fix(application): render rich HTML product descriptions with responsive typography styling
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s
Deploy Canina / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-08-29 08:55:55 +03:30
1 parent bfb7f42065
commit 05e26cab9f
15 files changed
+7717 -7136

No files matched your search

@@ -131,7 +131,7 @@ function ProductCard({ product }: { product: Product }) {
{/* Short description */}
<p className="text-xs-plus sm:text-xs text-medical-gray-500 leading-relaxed line-clamp-1 sm:line-clamp-2 flex-1">
{product.shortDescription || product.description || ''}
{product.shortDescription || (product.description ? product.description.replace(/<[^>]*>/g, '') : '')}
</p>
{/* Footer: Price + CTA */}
+23 -15
View File
@@ -495,29 +495,37 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{/* Comprehensive Product Description Section (Below the fold) */}
{fullProduct.description && (
<section className="bg-white border border-medical-gray-200 rounded-[1.5rem] sm:rounded-[2.5rem] p-4 sm:p-8 md:p-10 shadow-md space-y-3 sm:space-y-6">
<div className="flex items-center gap-3 sm:gap-4">
<div className="flex items-center gap-3 sm:gap-4 border-b border-medical-gray-100 pb-3 sm:pb-4">
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-canina-blue text-white rounded-xl sm:rounded-2xl flex items-center justify-center shadow-lg shrink-0">
<Info className="w-5 h-5 sm:w-6 sm:h-6" />
</div>
<h3 className="text-lg sm:text-2xl font-black text-medical-gray-900 italic font-vazir">توضیحات و معرفی محصول</h3>
</div>
<div className="text-xs sm:text-base text-medical-gray-600 font-medium leading-relaxed sm:leading-loose font-vazir space-y-2 sm:space-y-3 pt-2 sm:pt-3 border-t border-medical-gray-100 relative">
<div className="text-xs sm:text-base text-medical-gray-700 font-medium leading-relaxed sm:leading-loose font-vazir space-y-3 pt-2 relative">
{(() => {
const descText = fullProduct.description.trim();
const paragraphs = descText.split('\n').filter(Boolean);
const isLongText = descText.length > 180 || paragraphs.length > 1;
const isHtml = /<[a-z][\s\S]*>/i.test(descText);
const formattedHtml = isHtml
? descText
: descText.split('\n').filter(Boolean).map(p => `<p>${p.trim()}</p>`).join('');
const isLongText = descText.length > 400;
return (
<>
<div className="space-y-2 text-justify">
{isLongText && !isFullDescriptionOpen ? (
<p>
{descText.slice(0, 180)}...
</p>
) : (
paragraphs.map((para, pIdx) => (
<p key={pIdx}>{para.trim()}</p>
))
<div
className={`relative overflow-hidden transition-all duration-300 ${
isLongText && !isFullDescriptionOpen ? 'max-h-64' : 'max-h-none'
}`}
>
<div
dangerouslySetInnerHTML={{ __html: formattedHtml }}
className="rich-product-description space-y-3 font-vazir text-justify leading-relaxed sm:leading-loose [&>h1]:text-lg [&>h1]:sm:text-xl [&>h1]:font-black [&>h1]:text-medical-gray-900 [&>h1]:mt-4 [&>h1]:mb-2 [&>h2]:text-base [&>h2]:sm:text-lg [&>h2]:font-black [&>h2]:text-medical-gray-900 [&>h2]:mt-3 [&>h2]:mb-1.5 [&>h3]:text-sm [&>h3]:sm:text-base [&>h3]:font-black [&>h3]:text-medical-gray-900 [&>h3]:mt-3 [&>h3]:mb-1 [&>h4]:text-xs [&>h4]:sm:text-sm [&>h4]:font-bold [&>h4]:text-medical-gray-800 [&>p]:leading-relaxed [&>p]:sm:leading-loose [&>ul]:list-disc [&>ul]:pr-5 [&>ul]:space-y-1 [&>ol]:list-decimal [&>ol]:pr-5 [&>ol]:space-y-1 [&>table]:w-full [&>table]:border-collapse [&>table]:my-3 [&>table_th]:border [&>table_th]:border-medical-gray-200 [&>table_th]:p-2 [&>table_th]:bg-medical-gray-100 [&>table_td]:border [&>table_td]:border-medical-gray-200 [&>table_td]:p-2 [&>hr]:my-4 [&>hr]:border-medical-gray-200 [&>blockquote]:border-r-4 [&>blockquote]:border-canina-blue [&>blockquote]:pr-3 [&>blockquote]:italic [&>blockquote]:bg-canina-blue/5 [&>blockquote]:p-2 [&>blockquote]:rounded-l-lg [&>img]:rounded-xl [&>img]:my-3 [&>img]:max-w-full [&>img]:shadow-sm"
/>
{/* Gradient fade overlay when collapsed */}
{isLongText && !isFullDescriptionOpen && (
<div className="absolute inset-x-0 bottom-0 h-24 bg-gradient-to-t from-white via-white/90 to-transparent pointer-events-none" />
)}
</div>
@@ -526,7 +534,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<button
type="button"
onClick={() => setIsFullDescriptionOpen(prev => !prev)}
className="inline-flex items-center gap-1.5 px-4 py-2 bg-medical-gray-50 hover:bg-canina-blue/10 text-canina-blue rounded-xl text-xs font-black transition-all border border-medical-gray-200 hover:border-canina-blue/30 cursor-pointer"
className="inline-flex items-center gap-1.5 px-5 py-2.5 bg-medical-gray-50 hover:bg-canina-blue/10 text-canina-blue rounded-xl text-xs font-black transition-all border border-medical-gray-200 hover:border-canina-blue/30 cursor-pointer"
>
<span>{isFullDescriptionOpen ? 'بستن توضیحات' : 'مشاهده توضیحات کامل و بیشتر'}</span>
{isFullDescriptionOpen ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />}
@@ -1091,7 +1099,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
<div className="flex-1 text-center md:text-right">
<h4 className="text-xl font-black text-medical-gray-900 mb-2">{relProduct.name}</h4>
<p className="text-sm text-medical-gray-500 mb-6">{relProduct.description}</p>
<p className="text-sm text-medical-gray-500 mb-6">{relProduct.shortDescription || (relProduct.description ? relProduct.description.replace(/<[^>]*>/g, '') : '')}</p>
<div className="flex items-center justify-center md:justify-start gap-4">
<span className="text-lg font-black text-canina-blue">{relProduct.price}</span>
<ArrowRight className="w-4 h-4 text-medical-gray-300" />
@@ -437,7 +437,7 @@ export default function CatalogPageSpread({
</p>
)}
<p className="text-[9px] text-slate-500 font-medium line-clamp-2 leading-relaxed text-justify">
{product.shortDescription || product.description}
{product.shortDescription || (product.description ? product.description.replace(/<[^>]*>/g, '') : '')}
</p>
</div>
</div>
@@ -75,9 +75,16 @@ export default function ProductDetailModal({ product, categoryColor = "#0284C7",
<span className="text-xs font-black text-slate-400 uppercase tracking-widest block">
شرح بالینی و عملکرد:
</span>
<p className="text-sm text-slate-600 leading-relaxed font-medium">
{product.description}
</p>
{/<[a-z][\s\S]*>/i.test(product.description || '') ? (
<div
dangerouslySetInnerHTML={{ __html: product.description || '' }}
className="text-sm text-slate-600 leading-relaxed font-medium space-y-2 [&>h1]:font-black [&>h2]:font-black [&>h3]:font-black [&>p]:leading-relaxed [&>ul]:list-disc [&>ul]:pr-4 [&>ol]:list-decimal [&>ol]:pr-4 text-justify"
/>
) : (
<p className="text-sm text-slate-600 leading-relaxed font-medium text-justify">
{product.description}
</p>
)}
</div>
{/* Species & Dosage badges */}