Skip to content

Commit

Permalink
Escape certain characters for Markdown, fix antfu#13
Browse files Browse the repository at this point in the history
  • Loading branch information
rioj7 authored Nov 15, 2024
1 parent 96b7ebe commit 30f0404
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ function getConfigObject(packageJson: any) {
export function generateMarkdown(packageJson: any) {
const MAX_TABLE_COL_CHAR = 150

function markdownEscape(text: string) {
return text
.replace('&', '&')
.replace('<', '&lt;')
.replace('>', '&gt;')
.replace('|', '&vert;');
}

let commandsTable = [
['Command', 'Title'],
]
Expand All @@ -57,9 +65,9 @@ export function generateMarkdown(packageJson: any) {
...packageJson.contributes.commands.map((c: any) => {
return [
`\`${c.command}\``,
c.category
markdownEscape(c.category
? `${c.category}: ${c.title}`
: c.title,
: c.title),
]
}),
)
Expand All @@ -77,7 +85,7 @@ export function generateMarkdown(packageJson: any) {
const defaultVal = defaultValFromSchema(value) || ''
return [
`\`${key}\``,
value?.description || value?.markdownDescription || '',
markdownEscape(value?.description || value?.markdownDescription || ''),
`\`${String(value.type)}\``,
defaultVal.length < MAX_TABLE_COL_CHAR ? `\`${defaultVal}\`` : 'See package.json',
]
Expand Down

0 comments on commit 30f0404

Please sign in to comment.