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:
@@ -0,0 +1,83 @@
|
||||
/** هشدار، احتیاط، یا پیام منفی/ریسکی. */
|
||||
export const WARNING_PATTERNS: RegExp[] = [
|
||||
/هشدار/,
|
||||
/دقت کنید/,
|
||||
/توجه داشته باشید/,
|
||||
/مراقب باشید/,
|
||||
/خطر/,
|
||||
/\bنباید\b/,
|
||||
/\bهرگز\b/,
|
||||
/اشتباه رایج/,
|
||||
/از دست ندهید/,
|
||||
/پیش از آنکه/,
|
||||
/ممکن است منجر/,
|
||||
/فقط هزینه/,
|
||||
/پیچیدگی.*افزایش/,
|
||||
/افزایش میدهد/,
|
||||
/در چنین شرایطی/,
|
||||
/ریسک/,
|
||||
/مضر/,
|
||||
/نامناسب/,
|
||||
];
|
||||
|
||||
/** نکته کلیدی، جمعبندی مثبت، یا پیام ارزشمند. */
|
||||
export const POSITIVE_PATTERNS: RegExp[] = [
|
||||
/نکته کلیدی/,
|
||||
/نکته مهم/,
|
||||
/نکته اصلی/,
|
||||
/جمع.?بندی/,
|
||||
/پیشنهاد می/,
|
||||
/توصیه می/,
|
||||
/بهترین انتخاب/,
|
||||
/بهترین راه/,
|
||||
/\bحتماً\b/,
|
||||
/ارزش میآفریند/,
|
||||
/ارزشمند/,
|
||||
/ارزش واقعی/,
|
||||
/موفق.?ترین/,
|
||||
/هدف اصلی/,
|
||||
/نتیجه.?گیری/,
|
||||
/کلید موفقیت/,
|
||||
];
|
||||
|
||||
export type ContentTone = "warning" | "positive" | "neutral";
|
||||
|
||||
export function stripHtml(html: string): string {
|
||||
return html
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.replace(/ /gi, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function countPatternMatches(text: string, patterns: RegExp[]): number {
|
||||
return patterns.reduce(
|
||||
(count, pattern) => (pattern.test(text) ? count + 1 : count),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/** تشخیص لحن متن: هشدار، مثبت، یا خنثی. */
|
||||
export function detectContentTone(
|
||||
text: string,
|
||||
extra?: { warning?: RegExp[]; positive?: RegExp[] }
|
||||
): ContentTone {
|
||||
if (!text.trim()) {
|
||||
return "neutral";
|
||||
}
|
||||
|
||||
const warningPatterns = [...WARNING_PATTERNS, ...(extra?.warning ?? [])];
|
||||
const positivePatterns = [...POSITIVE_PATTERNS, ...(extra?.positive ?? [])];
|
||||
|
||||
const warningScore = countPatternMatches(text, warningPatterns);
|
||||
const positiveScore = countPatternMatches(text, positivePatterns);
|
||||
|
||||
if (warningScore > 0 && warningScore >= positiveScore) {
|
||||
return "warning";
|
||||
}
|
||||
if (positiveScore > 0) {
|
||||
return "positive";
|
||||
}
|
||||
|
||||
return "neutral";
|
||||
}
|
||||
Reference in New Issue
Block a user