Skip to content

Commit bc481d9

Browse files
fix: bold in tables (#1006)
[![PR App][icn]][demo] | CX-1153 :-------------------:|:----------: ## 🧰 Changes Fixes a regression when migrating tables with emphasis. The context for this is a bit long, but here's a summary: 1. magic block tables permitted block content 2. gfm tables did not 3. we dropped support for block content because the magic block implementation was problematic 4. users really want block content in tables, so we allowed breaks, `\n` 5. somewhere a long the line, the editor mucked up list like syntax in tables 6. I added a regex to look for that instance and correct it for the migration 7. that regex was not careful enough, and started matching emphasis 8. this PR fixes that to better not-match emphasis ## 🧬 QA & Testing - [Broken on production][prod]. - [Working in this PR app][demo]. [demo]: https://markdown-pr-PR_NUMBER.herokuapp.com [prod]: https://SUBDOMAIN.readme.io [icn]: https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
1 parent ead267e commit bc481d9

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

__tests__/migration/tables.test.ts

+124
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,128 @@ ${JSON.stringify(
334334
"
335335
`);
336336
});
337+
338+
it('compiles tables with emphasis without converting them to lists', () => {
339+
const md = `
340+
[block:parameters]
341+
{
342+
"data": {
343+
"h-0": "**Shortcut Name**",
344+
"h-1": "**WindowsOS**",
345+
"h-2": "_Apple - macOS_",
346+
"0-0": "*Cut selection*",
347+
"0-1": "__also__\\n\\n_no!_\\n\\n__no no no__",
348+
"0-2": "!BAD"
349+
},
350+
"cols": 3,
351+
"rows": 1,
352+
"align": [
353+
"left",
354+
"left",
355+
"left"
356+
]
357+
}
358+
[/block]
359+
`;
360+
361+
const mdx = rmdx.mdx(rmdx.mdastV6(md));
362+
363+
expect(mdx).toMatchInlineSnapshot(`
364+
"<Table align={["left","left","left"]}>
365+
<thead>
366+
<tr>
367+
<th style={{ textAlign: "left" }}>
368+
**Shortcut Name**
369+
</th>
370+
371+
<th style={{ textAlign: "left" }}>
372+
**WindowsOS**
373+
</th>
374+
375+
<th style={{ textAlign: "left" }}>
376+
*Apple - macOS*
377+
</th>
378+
</tr>
379+
</thead>
380+
381+
<tbody>
382+
<tr>
383+
<td style={{ textAlign: "left" }}>
384+
*Cut selection*
385+
</td>
386+
387+
<td style={{ textAlign: "left" }}>
388+
**also**
389+
390+
*no!*
391+
392+
**no no no**
393+
</td>
394+
395+
<td style={{ textAlign: "left" }}>
396+
!BAD
397+
</td>
398+
</tr>
399+
</tbody>
400+
</Table>
401+
"
402+
`);
403+
});
404+
405+
it('compiles more examples of emphasis', () => {
406+
const md = `
407+
[block:parameters]
408+
{
409+
"data": {
410+
"h-0": "Action",
411+
"h-1": "Description",
412+
"0-0": "Details",
413+
"0-1": "View additional details such as: \\n_Type_ \\n_Owner_ \\n_Created On_ \\n_Last Modified_ \\n_Last Run_"
414+
},
415+
"cols": 2,
416+
"rows": 1,
417+
"align": [
418+
"left",
419+
"left"
420+
]
421+
}
422+
[/block]
423+
`;
424+
425+
const mdx = rmdx.mdx(rmdx.mdastV6(md));
426+
427+
expect(mdx).toMatchInlineSnapshot(`
428+
"<Table align={["left","left"]}>
429+
<thead>
430+
<tr>
431+
<th style={{ textAlign: "left" }}>
432+
Action
433+
</th>
434+
435+
<th style={{ textAlign: "left" }}>
436+
Description
437+
</th>
438+
</tr>
439+
</thead>
440+
441+
<tbody>
442+
<tr>
443+
<td style={{ textAlign: "left" }}>
444+
Details
445+
</td>
446+
447+
<td style={{ textAlign: "left" }}>
448+
View additional details such as:\\
449+
*Type*\\
450+
*Owner*\\
451+
*Created On*\\
452+
*Last Modified*\\
453+
*Last Run*
454+
</td>
455+
</tr>
456+
</tbody>
457+
</Table>
458+
"
459+
`);
460+
});
337461
});

processor/migration/table-cell.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const magicIndex = (i: number, j: number) => `${i === 0 ? 'h' : `${i - 1}`}-${j}
2727
//
2828
// The following regex attempts to detect this pattern, and we'll convert it to
2929
// something more standard.
30-
const psuedoListRegex = /^(?!([*_]+).*\1$)(?<ws>[ \t]*)\\?([*_])\s*(?<item>.*)$/gm;
30+
const psuedoListRegex = /^(?![ \t]*([*_]+).*\1[ \t]*$)(?<ws>[ \t]*)\\?([*_])\s*(?<item>.*)$/gm;
3131

3232
const migrateTableCells = (vfile: VFile) => (table: Table) => {
3333
let json;

0 commit comments

Comments
 (0)