feat: auto-detect blockquote and table colors from content
Replace manual hashtags and color cycling with content-tone heuristics for blockquotes and tables, and refine blockquote layout with a centered icon, larger sizing, and clearer contrast over background decorations. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+66
-4
@@ -1,11 +1,73 @@
|
||||
import type { TableVariant } from "@/lib/blog-blocks";
|
||||
import { detectContentTone, stripHtml } from "@/lib/content-tone";
|
||||
|
||||
/** حذف برچسبهای انتخاب UI (#one, #two) از محتوای سلول جدول. */
|
||||
export function sanitizeTableCellContent(html: string): string {
|
||||
return html.replace(/#(?:one|two)\b/gi, "").trim();
|
||||
}
|
||||
|
||||
/** تشخیص variant جدول از متن خام (قبل از sanitize). */
|
||||
export function detectTableVariant(text: string): "one" | "two" {
|
||||
if (/#two\b/i.test(text)) return "two";
|
||||
if (/#one\b/i.test(text)) return "one";
|
||||
/** سیگنالهای هشدار مخصوص جدول (مقایسه، معایب، محدودیت). */
|
||||
const TABLE_WARNING_PATTERNS: RegExp[] = [
|
||||
/معایب/,
|
||||
/محدودیت/,
|
||||
/نکات منفی/,
|
||||
/هزینه.?ها/,
|
||||
/چالش.?ها/,
|
||||
/مشکلات/,
|
||||
/ضعف/,
|
||||
/منفی/,
|
||||
/اجتناب/,
|
||||
/اجتناب کنید/,
|
||||
];
|
||||
|
||||
/** سیگنالهای مثبت مخصوص جدول (مزایا، ویژگیها، پیشنهاد). */
|
||||
const TABLE_POSITIVE_PATTERNS: RegExp[] = [
|
||||
/مزایا/,
|
||||
/مزیت/,
|
||||
/ویژگی.?ها/,
|
||||
/قابلیت.?ها/,
|
||||
/پیشنهاد/,
|
||||
/بهترین/,
|
||||
/مزیت رقابتی/,
|
||||
/خلاصه/,
|
||||
];
|
||||
|
||||
function buildTableText(parts: {
|
||||
caption?: string;
|
||||
headers?: string[];
|
||||
rows?: string[][];
|
||||
}): string {
|
||||
const chunks = [
|
||||
parts.caption ?? "",
|
||||
...(parts.headers ?? []),
|
||||
...(parts.rows ?? []).flat(),
|
||||
];
|
||||
return stripHtml(chunks.join(" "));
|
||||
}
|
||||
|
||||
export interface DetectTableVariantInput {
|
||||
/** متن خام figure (برای override با #one/#two در محتوای قدیمی). */
|
||||
rawText?: string;
|
||||
caption?: string;
|
||||
headers?: string[];
|
||||
rows?: string[][];
|
||||
}
|
||||
|
||||
/**
|
||||
* تشخیص variant جدول: one = سبز (primary)، two = زرد (accent).
|
||||
* اولویت: hashtag صریح → هشدار → مثبت/خنثی (سبز).
|
||||
*/
|
||||
export function detectTableVariant(input: DetectTableVariantInput): TableVariant {
|
||||
const raw = input.rawText ?? "";
|
||||
if (/#two\b/i.test(raw)) return "two";
|
||||
if (/#one\b/i.test(raw)) return "one";
|
||||
|
||||
const text = buildTableText(input);
|
||||
const tone = detectContentTone(text, {
|
||||
warning: TABLE_WARNING_PATTERNS,
|
||||
positive: TABLE_POSITIVE_PATTERNS,
|
||||
});
|
||||
|
||||
if (tone === "warning") return "two";
|
||||
return "one";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user