added some text handling 3
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/** ساختار متن راهنما — توضیح + فرمول اختیاری در کادر جدا */
|
||||
|
||||
export type AdminHelpContent = {
|
||||
description: string
|
||||
formula?: string
|
||||
}
|
||||
|
||||
const FORMULA_MARKER = '\n\n__FORMULA__\n'
|
||||
|
||||
export function adminHelp(description: string, formula?: string): string {
|
||||
const body = description.trim()
|
||||
if (!formula?.trim()) return body
|
||||
return `${body}${FORMULA_MARKER}${formula.trim()}`
|
||||
}
|
||||
|
||||
export function parseAdminHelp(input: string | AdminHelpContent | undefined | null): AdminHelpContent {
|
||||
if (!input) return { description: '' }
|
||||
if (typeof input !== 'string') {
|
||||
return {
|
||||
description: input.description?.trim() ?? '',
|
||||
formula: input.formula?.trim() || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const marked = input.split(FORMULA_MARKER)
|
||||
if (marked.length === 2) {
|
||||
return {
|
||||
description: marked[0].trim(),
|
||||
formula: marked[1].trim() || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
return { description: input.trim() }
|
||||
}
|
||||
|
||||
export function adminHelpPlainText(content: AdminHelpContent): string {
|
||||
const parts = [content.description].filter(Boolean)
|
||||
if (content.formula) parts.push(content.formula)
|
||||
return parts.join('\n\n')
|
||||
}
|
||||
Reference in New Issue
Block a user