Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bold in tables #1006

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions __tests__/migration/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,128 @@ ${JSON.stringify(
"
`);
});

it('compiles tables with emphasis without converting them to lists', () => {
const md = `
[block:parameters]
{
"data": {
"h-0": "**Shortcut Name**",
"h-1": "**WindowsOS**",
"h-2": "_Apple - macOS_",
"0-0": "*Cut selection*",
"0-1": "__also__\\n\\n_no!_\\n\\n__no no no__",
"0-2": "!BAD"
},
"cols": 3,
"rows": 1,
"align": [
"left",
"left",
"left"
]
}
[/block]
`;

const mdx = rmdx.mdx(rmdx.mdastV6(md));

expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left","left"]}>
<thead>
<tr>
<th style={{ textAlign: "left" }}>
**Shortcut Name**
</th>

<th style={{ textAlign: "left" }}>
**WindowsOS**
</th>

<th style={{ textAlign: "left" }}>
*Apple - macOS*
</th>
</tr>
</thead>

<tbody>
<tr>
<td style={{ textAlign: "left" }}>
*Cut selection*
</td>

<td style={{ textAlign: "left" }}>
**also**

*no!*

**no no no**
</td>

<td style={{ textAlign: "left" }}>
!BAD
</td>
</tr>
</tbody>
</Table>
"
`);
});

it('compiles more examples of emphasis', () => {
const md = `
[block:parameters]
{
"data": {
"h-0": "Action",
"h-1": "Description",
"0-0": "Details",
"0-1": "View additional details such as: \\n_Type_ \\n_Owner_ \\n_Created On_ \\n_Last Modified_ \\n_Last Run_"
},
"cols": 2,
"rows": 1,
"align": [
"left",
"left"
]
}
[/block]
`;

const mdx = rmdx.mdx(rmdx.mdastV6(md));

expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
<tr>
<th style={{ textAlign: "left" }}>
Action
</th>

<th style={{ textAlign: "left" }}>
Description
</th>
</tr>
</thead>

<tbody>
<tr>
<td style={{ textAlign: "left" }}>
Details
</td>

<td style={{ textAlign: "left" }}>
View additional details such as:\\
*Type*\\
*Owner*\\
*Created On*\\
*Last Modified*\\
*Last Run*
</td>
</tr>
</tbody>
</Table>
"
`);
});
});
2 changes: 1 addition & 1 deletion processor/migration/table-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const magicIndex = (i: number, j: number) => `${i === 0 ? 'h' : `${i - 1}`}-${j}
//
// The following regex attempts to detect this pattern, and we'll convert it to
// something more standard.
const psuedoListRegex = /^(?!([*_]+).*\1$)(?<ws>[ \t]*)\\?([*_])\s*(?<item>.*)$/gm;
const psuedoListRegex = /^(?![ \t]*([*_]+).*\1[ \t]*$)(?<ws>[ \t]*)\\?([*_])\s*(?<item>.*)$/gm;

const migrateTableCells = (vfile: VFile) => (table: Table) => {
let json;
Expand Down