-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(remark): normalize tables output
- Loading branch information
Showing
8 changed files
with
195 additions
and
25 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,44 @@ | ||
import { consola } from 'consola'; | ||
import { glob } from 'glob'; | ||
import { remark } from 'remark'; | ||
import remarkMdx from 'remark-mdx'; | ||
import { read } from 'to-vfile'; | ||
|
||
const timeStart = new Date().getTime(); | ||
|
||
let error = false; | ||
|
||
consola.start(`Begin linting MDX...`); | ||
|
||
lintMdx(); | ||
|
||
async function lintMdx() { | ||
const mdFiles = await glob(`./test/out/**/*.md`); | ||
|
||
if (mdFiles.length === 0) { | ||
consola.error('No markdown files found'); | ||
throw new Error(); | ||
} | ||
|
||
mdFiles.forEach(async (file) => { | ||
const vfile = await read(file); | ||
try { | ||
await remark().use(remarkMdx).processSync(vfile); | ||
} catch (e) { | ||
error = true; | ||
consola.error(`Error linting MDX on file ${file}`); | ||
throw new Error(e); | ||
} | ||
}); | ||
} | ||
|
||
process.on('exit', () => { | ||
if (!error) { | ||
consola.success( | ||
`Finished linting MDX in ${( | ||
(new Date().getTime() - timeStart) / | ||
1000 | ||
).toFixed(2)} seconds`, | ||
); | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Normalize tables to have a newline before and after the content of each cell. | ||
* | ||
* This is necessary to ensure that the content of each cell is properly formatted by `htmlTable` formatting option | ||
* from typedoc-plugin-markdown is used. | ||
*/ | ||
export default function () { | ||
const compiler = this.compiler || this.Compiler; | ||
this.compiler = (tree) => { | ||
let content = compiler(tree); | ||
content = content | ||
.replace(/^\s*(<\/?(table|tr|th|td)>)/gm, (match, p1) => p1) | ||
.replace( | ||
/<td>\s*([\s\S]*?)\s*<\/td>/gm, | ||
(match, p1) => | ||
`<td>\n\n${p1 | ||
.split('\n') | ||
.map((line) => line.trim()) | ||
.join('\n')}\n\n</td>`, | ||
); | ||
return content; | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
export const someVariable = true; | ||
|
||
/** | ||
* @param param | ||
* | ||
* Default text content for `@category` tag. | ||
* | ||
* ```ts | ||
* const x = 1; | ||
* ``` | ||
*/ | ||
export function some_function(param: string) {} |
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