@@ -53,7 +53,9 @@ async function renderTable(markdown: string, conceal: boolean = true): Promise<s
5353 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
5454 await renderOnce ( )
5555
56- return "\n" + captureFrame ( ) . trimEnd ( )
56+ // Trim each line to remove terminal width padding
57+ const lines = captureFrame ( ) . split ( "\n" ) . map ( ( line ) => line . trimEnd ( ) )
58+ return "\n" + lines . join ( "\n" ) . trimEnd ( )
5759}
5860
5961test ( "basic table alignment" , async ( ) => {
@@ -64,9 +66,9 @@ test("basic table alignment", async () => {
6466
6567 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
6668 "
67- | Name | Age |
68- | ----- | --- |
69- | Alice | 30 |
69+ | Name | Age |
70+ | ----- | --- |
71+ | Alice | 30 |
7072 | Bob | 5 |"
7173 ` )
7274} )
@@ -80,10 +82,10 @@ test("table with inline code (backticks)", async () => {
8082
8183 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
8284 "
83- | Command | Description |
84- | ------------- | ------------- |
85- | npm install | Install deps |
86- | npm run build | Build project |
85+ | Command | Description |
86+ | ------------- | ------------- |
87+ | npm install | Install deps |
88+ | npm run build | Build project |
8789 | npm test | Run tests |"
8890 ` )
8991} )
@@ -96,9 +98,9 @@ test("table with bold text", async () => {
9698
9799 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
98100 "
99- | Feature | Status |
100- | -------------- | ------ |
101- | Authentication | Done |
101+ | Feature | Status |
102+ | -------------- | ------ |
103+ | Authentication | Done |
102104 | API | WIP |"
103105 ` )
104106} )
@@ -111,9 +113,9 @@ test("table with italic text", async () => {
111113
112114 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
113115 "
114- | Item | Note |
115- | ---- | --------- |
116- | One | important |
116+ | Item | Note |
117+ | ---- | --------- |
118+ | One | important |
117119 | Two | ok |"
118120 ` )
119121} )
@@ -126,9 +128,9 @@ test("table with mixed formatting", async () => {
126128
127129 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
128130 "
129- | Type | Value | Notes |
130- | ----- | ------ | ------ |
131- | Bold | code | italic |
131+ | Type | Value | Notes |
132+ | ----- | ------ | ------ |
133+ | Bold | code | italic |
132134 | Plain | strong | cmd |"
133135 ` )
134136} )
@@ -141,9 +143,9 @@ test("table with alignment markers (left, center, right)", async () => {
141143
142144 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
143145 "
144- | Left | Center | Right |
145- | :-------- | :----: | ----: |
146- | A | B | C |
146+ | Left | Center | Right |
147+ | :-------- | :----: | ----: |
148+ | A | B | C |
147149 | Long text | X | Y |"
148150 ` )
149151} )
@@ -156,9 +158,9 @@ test("table with empty cells", async () => {
156158
157159 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
158160 "
159- | A | B |
160- | --- | --- |
161- | X | |
161+ | A | B |
162+ | --- | --- |
163+ | X | |
162164 | | Y |"
163165 ` )
164166} )
@@ -170,8 +172,8 @@ test("table with long header and short content", async () => {
170172
171173 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
172174 "
173- | Very Long Column Header | Short |
174- | ----------------------- | ----- |
175+ | Very Long Column Header | Short |
176+ | ----------------------- | ----- |
175177 | A | B |"
176178 ` )
177179} )
@@ -183,8 +185,8 @@ test("table with short header and long content", async () => {
183185
184186 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
185187 "
186- | X | Y |
187- | ------------------------- | ----- |
188+ | X | Y |
189+ | ------------------------- | ----- |
188190 | This is very long content | Short |"
189191 ` )
190192} )
@@ -202,12 +204,12 @@ test("table inside code block should NOT be formatted", async () => {
202204
203205 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
204206 "
205- | Not | A | Table |
206- |---|---|---|
207- | Should | Stay | Raw |
208-
209- | Real | Table |
210- | ---- | --------- |
207+ | Not | A | Table |
208+ |---|---|---|
209+ | Should | Stay | Raw |
210+
211+ | Real | Table |
212+ | ---- | --------- |
211213 | Is | Formatted |"
212214 ` )
213215} )
@@ -225,13 +227,14 @@ Some text between.
225227
226228 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
227229 "
228- | Table1 | A |
229- | ------ | --- |
230- | X | Y |
231- Some text between.
232-
233- | Table2 | BB |
234- | ------------ | --- |
230+ | Table1 | A |
231+ | ------ | --- |
232+ | X | Y |
233+
234+ Some text between.
235+
236+ | Table2 | BB |
237+ | ------------ | --- |
235238 | Long content | Z |"
236239 ` )
237240} )
@@ -244,9 +247,9 @@ test("table with escaped pipe character", async () => {
244247
245248 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
246249 "
247- | Command | Output |
248- | ---------- | -------- |
249- | echo | Hello |
250+ | Command | Output |
251+ | ---------- | -------- |
252+ | echo | Hello |
250253 | ls \\| grep | Filtered |"
251254 ` )
252255} )
@@ -260,10 +263,10 @@ test("table with unicode characters", async () => {
260263
261264 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
262265 "
263- | Emoji | Name |
264- | ------ | -------- |
265- | 🎉 | Party |
266- | 🚀 | Rocket |
266+ | Emoji | Name |
267+ | ------ | -------- |
268+ | 🎉 | Party |
269+ | 🚀 | Rocket |
267270 | 日本語 | Japanese |"
268271 ` )
269272} )
@@ -276,9 +279,9 @@ test("table with links", async () => {
276279
277280 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
278281 "
279- | Name | Link |
280- | ------ | ------------------------ |
281- | Google | link (https://google.com) |
282+ | Name | Link |
283+ | ------ | ------------------------ |
284+ | Google | link (https://google.com) |
282285 | GitHub | gh (https://github.com) |"
283286 ` )
284287} )
@@ -289,7 +292,7 @@ test("single row table (header + delimiter only)", async () => {
289292
290293 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
291294 "
292- | Only | Header |
295+ | Only | Header |
293296 |---|---|"
294297 ` )
295298} )
@@ -301,8 +304,8 @@ test("table with many columns", async () => {
301304
302305 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
303306 "
304- | A | B | C | D | E |
305- | --- | --- | --- | --- | --- |
307+ | A | B | C | D | E |
308+ | --- | --- | --- | --- | --- |
306309 | 1 | 2 | 3 | 4 | 5 |"
307310 ` )
308311} )
@@ -316,10 +319,10 @@ Some paragraph text.
316319
317320 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
318321 "
319- Just a heading
320-
321- Some paragraph text.
322-
322+ Just a heading
323+
324+ Some paragraph text.
325+
323326 - List item"
324327 ` )
325328} )
@@ -332,9 +335,9 @@ test("table with nested inline formatting", async () => {
332335
333336 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
334337 "
335- | Description |
336- | ------------------------------- |
337- | This has bold and code together |
338+ | Description |
339+ | ------------------------------- |
340+ | This has bold and code together |
338341 | And italic with nested bold |"
339342 ` )
340343} )
@@ -349,9 +352,9 @@ test("conceal=false: table with bold text", async () => {
349352
350353 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
351354 "
352- | Feature | Status |
353- | ------------------ | ------ |
354- | **Authentication** | Done |
355+ | Feature | Status |
356+ | ------------------ | ------ |
357+ | **Authentication** | Done |
355358 | **API** | WIP |"
356359 ` )
357360} )
@@ -364,9 +367,9 @@ test("conceal=false: table with inline code", async () => {
364367
365368 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
366369 "
367- | Command | Description |
368- | --------------- | ------------- |
369- | \`npm install\` | Install deps |
370+ | Command | Description |
371+ | --------------- | ------------- |
372+ | \`npm install\` | Install deps |
370373 | \`npm run build\` | Build project |"
371374 ` )
372375} )
@@ -379,9 +382,9 @@ test("conceal=false: table with italic text", async () => {
379382
380383 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
381384 "
382- | Item | Note |
383- | ---- | ----------- |
384- | One | *important* |
385+ | Item | Note |
386+ | ---- | ----------- |
387+ | One | *important* |
385388 | Two | *ok* |"
386389 ` )
387390} )
@@ -394,9 +397,9 @@ test("conceal=false: table with mixed formatting", async () => {
394397
395398 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
396399 "
397- | Type | Value | Notes |
398- | -------- | ---------- | -------- |
399- | **Bold** | \`code\` | *italic* |
400+ | Type | Value | Notes |
401+ | -------- | ---------- | -------- |
402+ | **Bold** | \`code\` | *italic* |
400403 | Plain | **strong** | \`cmd\` |"
401404 ` )
402405} )
@@ -410,10 +413,10 @@ test("conceal=false: table with unicode characters", async () => {
410413
411414 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
412415 "
413- | Emoji | Name |
414- | ------ | -------- |
415- | 🎉 | Party |
416- | 🚀 | Rocket |
416+ | Emoji | Name |
417+ | ------ | -------- |
418+ | 🎉 | Party |
419+ | 🚀 | Rocket |
417420 | 日本語 | Japanese |"
418421 ` )
419422} )
@@ -426,9 +429,9 @@ test("conceal=false: basic table alignment", async () => {
426429
427430 expect ( await renderTable ( markdown , false ) ) . toMatchInlineSnapshot ( `
428431 "
429- | Name | Age |
430- | ----- | --- |
431- | Alice | 30 |
432+ | Name | Age |
433+ | ----- | --- |
434+ | Alice | 30 |
432435 | Bob | 5 |"
433436 ` )
434437} )
@@ -444,12 +447,12 @@ This is a paragraph after the table.`
444447
445448 expect ( await renderTable ( markdown ) ) . toMatchInlineSnapshot ( `
446449 "
447- This is a paragraph before the table.
448-
449- | Name | Age |
450- | ----- | --- |
451- | Alice | 30 |
452-
450+ This is a paragraph before the table.
451+
452+ | Name | Age |
453+ | ----- | --- |
454+ | Alice | 30 |
455+
453456 This is a paragraph after the table."
454457 ` )
455458} )
0 commit comments