@@ -4,7 +4,6 @@ import { t } from "../i18n/index.ts";
44import { copyToClipboard } from "../lib/clipboard.ts" ;
55import { toolIcons } from "./icons-tools.ts" ;
66import { icons } from "./icons.ts" ;
7- import type { MarkdownRenderEnv } from "./markdown-render-options.ts" ;
87import { escapeMarkdownHtml } from "./markdown-text.ts" ;
98
109const tableShellSelector = ".chat-text .markdown-table[data-table-interactions]" ;
@@ -19,17 +18,26 @@ type TableOwnerState = {
1918 observedViewports : Set < HTMLElement > ;
2019} ;
2120
21+ function tableInteractionsEnabled ( env : unknown ) : boolean {
22+ return (
23+ typeof env === "object" &&
24+ env !== null &&
25+ "tableInteractions" in env &&
26+ env . tableInteractions === "enabled"
27+ ) ;
28+ }
29+
2230export function installMarkdownTables ( markdownParser : MarkdownIt ) : void {
2331 const defaultTableOpen = markdownParser . renderer . rules . table_open ;
2432 const defaultTableClose = markdownParser . renderer . rules . table_close ;
2533 markdownParser . renderer . rules . table_open = ( tokens , index , options , env , renderer ) => {
26- if ( ( env as Partial < MarkdownRenderEnv > ) . tableInteractions !== "enabled" ) {
34+ if ( ! tableInteractionsEnabled ( env ) ) {
2735 return defaultTableOpen ?.( tokens , index , options , env , renderer ) ?? "<table>\n" ;
2836 }
2937 return '<div class="markdown-table" data-table-interactions><div class="markdown-table__viewport"><table>' ;
3038 } ;
3139 markdownParser . renderer . rules . table_close = ( tokens , index , options , env , renderer ) => {
32- if ( ( env as Partial < MarkdownRenderEnv > ) . tableInteractions !== "enabled" ) {
40+ if ( ! tableInteractionsEnabled ( env ) ) {
3341 return defaultTableClose ?.( tokens , index , options , env , renderer ) ?? "</table>\n" ;
3442 }
3543 return `</table></div><div class="markdown-table__actions"><button type="button" class="markdown-table__expand" aria-label="${ escapeMarkdownHtml ( t ( "common.expandTable" ) ) } "></button><button type="button" class="markdown-table__copy" aria-label="${ escapeMarkdownHtml ( t ( "common.copyTable" ) ) } "></button></div></div>` ;
0 commit comments