mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 20:40:23 +00:00
refactor(deadcode): drop orphaned extension helpers
This commit is contained in:
@@ -2,15 +2,6 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
escapeNextcloudTalkMarkdown,
|
||||
formatNextcloudTalkCodeBlock,
|
||||
formatNextcloudTalkInlineCode,
|
||||
formatNextcloudTalkMention,
|
||||
markdownToNextcloudTalk,
|
||||
stripNextcloudTalkFormatting,
|
||||
truncateNextcloudTalkText,
|
||||
} from "./format.js";
|
||||
import {
|
||||
looksLikeNextcloudTalkTargetId,
|
||||
normalizeNextcloudTalkMessagingTarget,
|
||||
@@ -73,30 +64,6 @@ async function makeTempDir(): Promise<string> {
|
||||
}
|
||||
|
||||
describe("nextcloud talk core", () => {
|
||||
it("accepts SecretRef botSecret and apiPassword at top-level", () => {
|
||||
expect(markdownToNextcloudTalk(" **hello** ")).toBe("**hello**");
|
||||
});
|
||||
|
||||
it("escapes markdown-sensitive characters", () => {
|
||||
expect(escapeNextcloudTalkMarkdown("*hello* [x](y)")).toBe("\\*hello\\* \\[x\\]\\(y\\)");
|
||||
});
|
||||
|
||||
it("formats mentions and code consistently", () => {
|
||||
expect(formatNextcloudTalkMention("@alice")).toBe("@alice");
|
||||
expect(formatNextcloudTalkMention("bob")).toBe("@bob");
|
||||
expect(formatNextcloudTalkCodeBlock("const x = 1;", "ts")).toBe("```ts\nconst x = 1;\n```");
|
||||
expect(formatNextcloudTalkInlineCode("x")).toBe("`x`");
|
||||
expect(formatNextcloudTalkInlineCode("x ` y")).toBe("`` x ` y ``");
|
||||
});
|
||||
|
||||
it("strips markdown formatting and truncates on word boundaries", () => {
|
||||
expect(stripNextcloudTalkFormatting("**bold** [link](https://example.com) `code`")).toBe(
|
||||
"bold link",
|
||||
);
|
||||
expect(truncateNextcloudTalkText("alpha beta gamma delta", 14)).toBe("alpha beta...");
|
||||
expect(truncateNextcloudTalkText("short", 14)).toBe("short");
|
||||
});
|
||||
|
||||
it("builds an outbound session route for normalized room targets", () => {
|
||||
const route = resolveNextcloudTalkOutboundSessionRoute({
|
||||
cfg: {},
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/**
|
||||
* Format utilities for Nextcloud Talk messages.
|
||||
*
|
||||
* Nextcloud Talk supports markdown natively, so most formatting passes through.
|
||||
* This module handles any edge cases or transformations needed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert markdown to Nextcloud Talk compatible format.
|
||||
* Nextcloud Talk supports standard markdown, so minimal transformation needed.
|
||||
*/
|
||||
export function markdownToNextcloudTalk(text: string): string {
|
||||
return text.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special characters in text to prevent markdown interpretation.
|
||||
*/
|
||||
export function escapeNextcloudTalkMarkdown(text: string): string {
|
||||
return text.replace(/([*_`~[\]()#>+\-=|{}!\\])/g, "\\$1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a mention for a Nextcloud user.
|
||||
* Nextcloud Talk uses @user format for mentions.
|
||||
*/
|
||||
export function formatNextcloudTalkMention(userId: string): string {
|
||||
return `@${userId.replace(/^@/, "")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a code block for Nextcloud Talk.
|
||||
*/
|
||||
export function formatNextcloudTalkCodeBlock(code: string, language?: string): string {
|
||||
const lang = language ?? "";
|
||||
return `\`\`\`${lang}\n${code}\n\`\`\``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format inline code for Nextcloud Talk.
|
||||
*/
|
||||
export function formatNextcloudTalkInlineCode(code: string): string {
|
||||
if (code.includes("`")) {
|
||||
return `\`\` ${code} \`\``;
|
||||
}
|
||||
return `\`${code}\``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip Nextcloud Talk specific formatting from text.
|
||||
* Useful for extracting plain text content.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate text to a maximum length, preserving word boundaries.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user