Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/spec-node/collectionCommonUtils/generateDocsCommandImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ async function _generateDocumentation(

let newReadme = readmeTemplate
// Templates & Features
.replace('#{Id}', parsedJson.id)
.replace('#{Name}', parsedJson.name ? `${parsedJson.name} (${parsedJson.id})` : `${parsedJson.id}`)
.replace('#{Description}', parsedJson.description ?? '')
.replace('#{OptionsTable}', generateOptionsMarkdown())
.replace('#{Notes}', generateNotesMarkdown())
.replace('#{RepoUrl}', urlToConfig)
.replace('#{Id}', () => parsedJson.id)
.replace('#{Name}', () => parsedJson.name ? `${parsedJson.name} (${parsedJson.id})` : `${parsedJson.id}`)
.replace('#{Description}', () => parsedJson.description ?? '')
.replace('#{OptionsTable}', () => generateOptionsMarkdown())
.replace('#{Notes}', () => generateNotesMarkdown())
.replace('#{RepoUrl}', () => urlToConfig)
// Features Only
.replace('#{Registry}', ociRegistry)
.replace('#{Namespace}', namespace)
.replace('#{Version}', version)
.replace('#{Customizations}', extensions);
.replace('#{Registry}', () => ociRegistry)
.replace('#{Namespace}', () => namespace)
.replace('#{Version}', () => version)
.replace('#{Customizations}', () => extensions);

if (header) {
newReadme = header + newReadme;
Expand Down
34 changes: 33 additions & 1 deletion src/test/container-features/featuresCLICommands.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert } from 'chai';
import path from 'path';
import { existsSync } from 'fs';
import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
import os from 'os';
import { createPlainLog, LogLevel, makeLog } from '../../spec-utils/log';
import { isLocalFile, readLocalFile } from '../../spec-utils/pfs';
import { createTestCommonParams, ExecResult, shellExec } from '../testUtils';
Expand Down Expand Up @@ -814,4 +815,35 @@ describe('tests generateFeaturesDocumentation()', async function () {
const invalidDocsExists = await isLocalFile(`${projectFolder}/not-a-feature/README.md`);
assert.isFalse(invalidDocsExists);
});

it('preserves dollar sequences in generated feature documentation', async function () {
const basePath = mkdtempSync(path.join(os.tmpdir(), 'devcontainer-feature-docs-'));
const featurePath = path.join(basePath, 'dollar-content');
mkdirSync(featurePath);
writeFileSync(path.join(featurePath, 'devcontainer-feature.json'), JSON.stringify({
id: 'dollar-content',
version: '1.0.0',
name: 'Price $&',
description: 'Keep $\' literally',
options: {
example: {
type: 'string',
description: 'Keep $\' and $$ literally',
},
},
}));
writeFileSync(path.join(featurePath, 'NOTES.md'), 'Keep $` and $$ literally.');

try {
await generateFeaturesDocumentation(basePath, 'ghcr.io', 'devcontainers/cli', 'devcontainers', 'cli', output);
const readme = readFileSync(path.join(featurePath, 'README.md'), 'utf8');
assert.include(readme, '# Price $& (dollar-content)');
assert.include(readme, 'Keep $\' literally');
assert.include(readme, 'Keep $\' and $$ literally');
assert.include(readme, 'Keep $` and $$ literally.');
assert.strictEqual((readme.match(/## Example Usage/g) ?? []).length, 1);
} finally {
rmSync(basePath, { recursive: true, force: true });
}
});
});