Skip to content

Commit 1092cb0

Browse files
fix: more tweaks
1 parent ecc80f0 commit 1092cb0

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/markdown/command.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ export class MarkdownCommand extends MarkdownBase {
4444
outputDir: string
4545
) {
4646
const commandWithUnderscores = ensureString(command.id).replace(/:/g, '_');
47-
const filename = MarkdownBase.file(`cli_reference_${commandWithUnderscores}`);
47+
// If the command ID has no subtopic (e.g. "doctor"), its filename would collide with the topic
48+
// index file (cli_reference_doctor.md), so append _command to disambiguate.
49+
const isTopicLevelCommand = !ensureString(command.id).includes(':');
50+
const baseName = isTopicLevelCommand
51+
? `cli_reference_${commandWithUnderscores}_command`
52+
: `cli_reference_${commandWithUnderscores}`;
53+
const filename = MarkdownBase.file(baseName);
4854
super(filename, outputDir);
4955
this.destination = join(outputDir, topic, filename);
5056

@@ -112,8 +118,10 @@ export class MarkdownCommand extends MarkdownBase {
112118
if (this.help.length > 0) {
113119
lines.push(`## Description for ${this.commandName}`);
114120
lines.push('');
115-
for (const paragraph of this.help) {
116-
lines.push(applyCodeFormatting(escapeAngleBrackets(paragraph)));
121+
for (const paragraph of convertHyphenListsToMarkdown(
122+
this.help.map((p) => applyCodeFormatting(escapeAngleBrackets(p)))
123+
)) {
124+
lines.push(paragraph);
117125
lines.push('');
118126
}
119127
}
@@ -162,12 +170,37 @@ function applyCodeFormatting(text: string): string {
162170
let result = text.replace(/(?<!`)--([\w-]+)(?!`)/g, '`--$1`');
163171
// Wrap glob patterns like *.cls, *.trigger (not already in backticks)
164172
result = result.replace(/(?<!`)\*(\.\w+)(?!`)/g, '`*$1`');
173+
// Wrap filenames/extensions with known doc-related extensions (not already in backticks)
174+
// Must run compound extensions (.sarif.json) before simple ones (.sarif, .json)
175+
result = result.replace(/(?<![\w`])(\.sarif\.json)(?![\w`])/g, '`$1`');
176+
result = result.replace(/(?<![\w`])(\w[\w.-]*\.(?:xml|html?|json|sarif|csv))(?![\w`])/g, '`$1`');
177+
result = result.replace(/(?<![\w`])(\.(?:xml|html?|json|sarif|csv))(?![\w`])/g, '`$1`');
165178
// Wrap file/directory paths: must be preceded by whitespace or opening punctuation (not part of a URL)
166179
// Matches: ./foo/bar, ../foo, foo/bar/baz — but not https://foo/bar
167180
result = result.replace(/(^|(?<=[\s(["]))(?!https?:\/\/)((?:\.{1,2}\/|[\w][\w-]*\/)[\w./-]+)/g, '$1`$2`');
168181
return result;
169182
}
170183

184+
function convertHyphenListsToMarkdown(paragraphs: string[]): string[] {
185+
const result: string[] = [];
186+
let i = 0;
187+
while (i < paragraphs.length) {
188+
if (paragraphs[i].startsWith('- ')) {
189+
// Collect consecutive list items and join with <br> for table cell rendering
190+
const items: string[] = [];
191+
while (i < paragraphs.length && paragraphs[i].startsWith('- ')) {
192+
items.push(paragraphs[i]);
193+
i++;
194+
}
195+
result.push(items.join('<br>'));
196+
} else {
197+
result.push(paragraphs[i]);
198+
i++;
199+
}
200+
}
201+
return result;
202+
}
203+
171204
function resolveStateLabel(state: unknown, deprecated: boolean): string | null {
172205
if (deprecated) return 'Deprecated';
173206
if (state === 'beta') return 'Beta';
@@ -232,9 +265,9 @@ function renderFlagDescription(param: CommandParameterData): string {
232265
parts.push(`**Valid Values:** ${param.options.map((o) => `\`${o}\``).join(', ')}`);
233266
}
234267
if (param.defaultFlagValue) parts.push(`**Default value:** \`${param.defaultFlagValue}\``);
235-
const desc = param.description
236-
.map((p) => applyCodeFormatting(escapeAngleBrackets(p.replace(/\|/g, '&#124;'))))
237-
.join('<br><br>');
268+
const desc = convertHyphenListsToMarkdown(
269+
param.description.map((p) => applyCodeFormatting(escapeAngleBrackets(p.replace(/\|/g, '&#124;'))))
270+
).join('<br><br>');
238271
if (desc) parts.push(desc);
239272
return parts.join('<br>').replace(/\n/g, ' ');
240273
}

src/markdown/toc.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ export class MarkdownToc extends MarkdownBase {
5959
: state && STATE_LABELS[state]
6060
? ` (${STATE_LABELS[state]})`
6161
: '';
62+
const isTopicLevelCommand = !id.includes(':');
63+
const linkTarget = isTopicLevelCommand
64+
? `cli_reference_${commandWithUnderscores}_command.md`
65+
: `cli_reference_${commandWithUnderscores}.md`;
6266
lines.push(` - title: ${commandWithSpaces}${stateLabel}`);
63-
lines.push(` link: ${topic}/cli_reference_${commandWithUnderscores}.md`);
67+
lines.push(` link: ${topic}/${linkTarget}`);
6468
}
6569
}
6670

src/markdown/topic-index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export class MarkdownTopicIndex extends MarkdownBase {
4141
for (const id of [...this.commandIds].sort()) {
4242
const commandWithUnderscores = id.replace(/:/g, '_');
4343
const commandWithSpaces = id.replace(/:/g, ' ');
44-
lines.push(`- [${commandWithSpaces}](./cli_reference_${commandWithUnderscores}.md)`);
44+
const isTopicLevelCommand = !id.includes(':');
45+
const linkTarget = isTopicLevelCommand
46+
? `cli_reference_${commandWithUnderscores}_command.md`
47+
: `cli_reference_${commandWithUnderscores}.md`;
48+
lines.push(`- [${commandWithSpaces}](./${linkTarget})`);
4549
}
4650
lines.push('');
4751
return Promise.resolve(lines.join('\n'));

0 commit comments

Comments
 (0)