-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): improved tables functionality
- Loading branch information
Showing
39 changed files
with
713 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/typedoc-plugin-markdown/src/libs/markdown/html-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function htmlTable( | ||
headers: string[], | ||
rows: string[][], | ||
leftAlignHeadings = false, | ||
) { | ||
return `<table> | ||
<tr>${headers.map((header) => `<th${leftAlignHeadings ? ' align="left"' : ''}>${header}</th>`).join('')}</tr>${rows | ||
.map( | ||
(row) => | ||
` | ||
<tr>${row | ||
.map( | ||
(cell) => | ||
` | ||
<td> | ||
${cell === '-' ? '‐' : cell} | ||
</td>`, | ||
) | ||
.join('')} | ||
</tr>`, | ||
) | ||
.join('')} | ||
</table>`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
packages/typedoc-plugin-markdown/src/libs/markdown/table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { formatTableCell } from '../utils/format-table-cell'; | ||
/** | ||
* Comments for table | ||
* @param headers | ||
* @param rows | ||
*/ | ||
export function table(headers: string[], rows: string[][]) { | ||
export function table( | ||
headers: string[], | ||
rows: string[][], | ||
headerLeftAlign = false, | ||
) { | ||
return `\n| ${headers.join(' | ')} |\n| ${headers | ||
.map(() => ':------') | ||
.join(' | ')} |\n${rows.map((row) => `| ${row.join(' | ')} |\n`).join('')}`; | ||
.map(() => `${headerLeftAlign ? ':' : ''}------`) | ||
.join( | ||
' | ', | ||
)} |\n${rows.map((row) => `| ${row.map((cell) => formatTableCell(cell)).join(' | ')} |\n`).join('')}`; | ||
} |
26 changes: 0 additions & 26 deletions
26
packages/typedoc-plugin-markdown/src/libs/utils/format-markdown.spec.ts
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { formatTableCell } from './format-table-cell'; | ||
|
||
describe('formatTableCell', () => { | ||
it('should correctly format the cell content', () => { | ||
const input = ` | ||
This is a test | ||
\`\`\`ts | ||
const x = 10; | ||
\`\`\` | ||
with multiple spaces. | ||
`; | ||
const expectedOutput = | ||
'This is a test `const x = 10;` with multiple spaces.'; | ||
expect(formatTableCell(input)).toBe(expectedOutput); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* - Replace new lines with spaces | ||
* - Replaces code blocks with single backticks | ||
* - Replaces multiple spaces with single spaces | ||
*/ | ||
export function formatTableCell(str: string) { | ||
return str | ||
.replace(/\n/g, ' ') | ||
.replace( | ||
/```(\w+\s)?([\s\S]*?)```/gs, | ||
(match, p1, p2) => `\`${p2.trim()}\``, | ||
) | ||
.replace(/ +/g, ' ') | ||
.trim(); | ||
} |
16 changes: 0 additions & 16 deletions
16
packages/typedoc-plugin-markdown/src/libs/utils/format-table-column.spec.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/typedoc-plugin-markdown/src/libs/utils/format-table-column.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
packages/typedoc-plugin-markdown/src/libs/utils/markdown-blocks-to-html.spec.ts
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
packages/typedoc-plugin-markdown/src/libs/utils/markdown-blocks-to-html.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.