-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,366 additions
and
725 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'typedoc-plugin-markdown': patch | ||
--- | ||
|
||
- Remove superfluous quotes from prop names (#619) | ||
- Fix display of index descriptions in tables (#618) |
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
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(); | ||
} |
22 changes: 0 additions & 22 deletions
22
packages/typedoc-plugin-markdown/src/libs/utils/format-table-column.spec.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
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
24 changes: 24 additions & 0 deletions
24
packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.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,24 @@ | ||
import { normalizeLineBreaks } from './normalize-line-breaks'; | ||
|
||
describe('normalizeLineBreaks', () => { | ||
it('should correctly concatenate lines', () => { | ||
const input = `This line should be concatenated with the next one. | ||
The next line. | ||
This is the next line double break. | ||
- list item 1 | ||
- list item 2 | ||
This is another test.`; | ||
|
||
const expectedOutput = `This line should be concatenated with the next one. The next line. | ||
This is the next line double break. | ||
- list item 1 | ||
- list item 2 | ||
This is another test.`; | ||
|
||
expect(normalizeLineBreaks(input)).toBe(expectedOutput); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.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,38 @@ | ||
export function normalizeLineBreaks(str: string): string { | ||
const codeBlocks: string[] = []; | ||
|
||
const placeholder = '\n___CODEBLOCKPLACEHOLDER___\n'; | ||
str = str.replace(/```[\s\S]*?```/g, (match) => { | ||
codeBlocks.push(match); | ||
return placeholder; | ||
}); | ||
|
||
const lines = str.split('\n'); | ||
let result = ''; | ||
for (let i = 0; i < lines.length; i++) { | ||
if (lines[i].length === 0) { | ||
result = result + lines[i] + '\n'; | ||
} else { | ||
if ( | ||
!lines[i].startsWith('#') && | ||
lines[i + 1] && | ||
/^[a-zA-Z`]/.test(lines[i + 1]) | ||
) { | ||
result = result + lines[i] + ' '; | ||
} else { | ||
if (i < lines.length - 1) { | ||
result = result + lines[i] + '\n'; | ||
} else { | ||
result = result + lines[i]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
result = result.replace( | ||
new RegExp(placeholder, 'g'), | ||
() => `${codeBlocks.shift()}` || '', | ||
); | ||
|
||
return result; | ||
} |
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
Oops, something went wrong.