fix: add per-channel markdown table conversion (#1495) (thanks @odysseus0)

This commit is contained in:
Peter Steinberger
2026-01-23 17:56:50 +00:00
parent 37e5f077b8
commit b77e730657
64 changed files with 837 additions and 186 deletions

View File

@@ -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));