| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| export function markdownToNextcloudTalk(text: string): string { |
| return text.trim(); |
| } |
|
|
| |
| |
| |
| export function escapeNextcloudTalkMarkdown(text: string): string { |
| return text.replace(/([*_`~[\]()#>+\-=|{}!\\])/g, "\\$1"); |
| } |
|
|
| |
| |
| |
| |
| export function formatNextcloudTalkMention(userId: string): string { |
| return `@${userId.replace(/^@/, "")}`; |
| } |
|
|
| |
| |
| |
| export function formatNextcloudTalkCodeBlock(code: string, language?: string): string { |
| const lang = language ?? ""; |
| return `\`\`\`${lang}\n${code}\n\`\`\``; |
| } |
|
|
| |
| |
| |
| export function formatNextcloudTalkInlineCode(code: string): string { |
| if (code.includes("`")) { |
| return `\`\` ${code} \`\``; |
| } |
| return `\`${code}\``; |
| } |
|
|
| |
| |
| |
| |
| export function stripNextcloudTalkFormatting(text: string): string { |
| return text |
| .replace(/```[\s\S]*?```/g, "") |
| .replace(/`[^`]+`/g, "") |
| .replace(/\*\*([^*]+)\*\*/g, "$1") |
| .replace(/\*([^*]+)\*/g, "$1") |
| .replace(/_([^_]+)_/g, "$1") |
| .replace(/~~([^~]+)~~/g, "$1") |
| .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") |
| .replace(/\s+/g, " ") |
| .trim(); |
| } |
|
|
| |
| |
| |
| export function truncateNextcloudTalkText(text: string, maxLength: number, suffix = "..."): string { |
| if (text.length <= maxLength) { |
| return text; |
| } |
| const truncated = text.slice(0, maxLength - suffix.length); |
| const lastSpace = truncated.lastIndexOf(" "); |
| if (lastSpace > maxLength * 0.7) { |
| return truncated.slice(0, lastSpace) + suffix; |
| } |
| return truncated + suffix; |
| } |
|
|