MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / MarkdownTable

Function MarkdownTable

source code/components/MarkdownTable.tsx:74–323  ·  view source on GitHub ↗
({
  token,
  highlight,
  forceWidth
}: Props)

Source from the content-addressed store, hash-verified

72 * 4. Properly aligning multi-line rows with borders
73 */
74export function MarkdownTable({
75 token,
76 highlight,
77 forceWidth
78}: Props): React.ReactNode {
79 const [theme] = useTheme();
80 const {
81 columns: actualTerminalWidth
82 } = useTerminalSize();
83 const terminalWidth = forceWidth ?? actualTerminalWidth;
84
85 // Format cell content to ANSI string
86 function formatCell(tokens: Token[] | undefined): string {
87 return tokens?.map(_ => formatToken(_, theme, 0, null, null, highlight)).join('') ?? '';
88 }
89
90 // Get plain text (stripped of ANSI codes)
91 function getPlainText(tokens_0: Token[] | undefined): string {
92 return stripAnsi(formatCell(tokens_0));
93 }
94
95 // Get the longest word width in a cell (minimum width to avoid breaking words)
96 function getMinWidth(tokens_1: Token[] | undefined): number {
97 const text = getPlainText(tokens_1);
98 const words = text.split(/\s+/).filter(w => w.length > 0);
99 if (words.length === 0) return MIN_COLUMN_WIDTH;
100 return Math.max(...words.map(w_0 => stringWidth(w_0)), MIN_COLUMN_WIDTH);
101 }
102
103 // Get ideal width (full content without wrapping)
104 function getIdealWidth(tokens_2: Token[] | undefined): number {
105 return Math.max(stringWidth(getPlainText(tokens_2)), MIN_COLUMN_WIDTH);
106 }
107
108 // Calculate column widths
109 // Step 1: Get minimum (longest word) and ideal (full content) widths
110 const minWidths = token.header.map((header, colIndex) => {
111 let maxMinWidth = getMinWidth(header.tokens);
112 for (const row of token.rows) {
113 maxMinWidth = Math.max(maxMinWidth, getMinWidth(row[colIndex]?.tokens));
114 }
115 return maxMinWidth;
116 });
117 const idealWidths = token.header.map((header_0, colIndex_0) => {
118 let maxIdeal = getIdealWidth(header_0.tokens);
119 for (const row_0 of token.rows) {
120 maxIdeal = Math.max(maxIdeal, getIdealWidth(row_0[colIndex_0]?.tokens));
121 }
122 return maxIdeal;
123 });
124
125 // Step 2: Calculate available space
126 // Border overhead: │ content │ content │ = 1 + (width + 3) per column
127 const numCols = token.header.length;
128 const borderOverhead = 1 + numCols * 3; // │ + (2 padding + 1 border) per col
129 // Account for SAFETY_MARGIN to avoid triggering the fallback safety check
130 const availableWidth = Math.max(terminalWidth - borderOverhead - SAFETY_MARGIN, numCols * MIN_COLUMN_WIDTH);
131

Callers

nothing calls this directly

Calls 9

useThemeFunction · 0.85
useTerminalSizeFunction · 0.85
getMinWidthFunction · 0.85
getIdealWidthFunction · 0.85
calculateMaxRowLinesFunction · 0.85
renderVerticalFormatFunction · 0.85
renderBorderLineFunction · 0.85
renderRowLinesFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected