mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:21:26 +00:00
fix: add per-channel markdown table conversion (#1495) (thanks @odysseus0)
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
type MarkdownIR,
|
||||
type MarkdownStyle,
|
||||
} from "../markdown/ir.js";
|
||||
import type { MarkdownTableMode } from "../config/types.base.js";
|
||||
|
||||
type SignalTextStyle = "BOLD" | "ITALIC" | "STRIKETHROUGH" | "MONOSPACE" | "SPOILER";
|
||||
|
||||
@@ -18,6 +19,10 @@ export type SignalFormattedText = {
|
||||
styles: SignalTextStyleRange[];
|
||||
};
|
||||
|
||||
type SignalMarkdownOptions = {
|
||||
tableMode?: MarkdownTableMode;
|
||||
};
|
||||
|
||||
type SignalStyleSpan = {
|
||||
start: number;
|
||||
end: number;
|
||||
@@ -188,22 +193,31 @@ function renderSignalText(ir: MarkdownIR): SignalFormattedText {
|
||||
};
|
||||
}
|
||||
|
||||
export function markdownToSignalText(markdown: string): SignalFormattedText {
|
||||
export function markdownToSignalText(
|
||||
markdown: string,
|
||||
options: SignalMarkdownOptions = {},
|
||||
): SignalFormattedText {
|
||||
const ir = markdownToIR(markdown ?? "", {
|
||||
linkify: true,
|
||||
enableSpoilers: true,
|
||||
headingStyle: "none",
|
||||
blockquotePrefix: "",
|
||||
tableMode: options.tableMode,
|
||||
});
|
||||
return renderSignalText(ir);
|
||||
}
|
||||
|
||||
export function markdownToSignalTextChunks(markdown: string, limit: number): SignalFormattedText[] {
|
||||
export function markdownToSignalTextChunks(
|
||||
markdown: string,
|
||||
limit: number,
|
||||
options: SignalMarkdownOptions = {},
|
||||
): SignalFormattedText[] {
|
||||
const ir = markdownToIR(markdown ?? "", {
|
||||
linkify: true,
|
||||
enableSpoilers: true,
|
||||
headingStyle: "none",
|
||||
blockquotePrefix: "",
|
||||
tableMode: options.tableMode,
|
||||
});
|
||||
const chunks = chunkMarkdownIR(ir, limit);
|
||||
return chunks.map((chunk) => renderSignalText(chunk));
|
||||
|
||||
Reference in New Issue
Block a user