mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: honor the CLI end-of-options marker (#4230)
* fix: honor the CLI end-of-options marker Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: cover hyphen-prefixed input files after -- Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * docs: document the CLI option terminator Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --------- Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
This commit is contained in:
co-authored by
GeneralTony007
parent
c6b22e89ba
commit
a1ddc722e7
@@ -98,6 +98,10 @@ export async function main(nodeProcess) {
|
||||
}
|
||||
|
||||
while (argv.length) {
|
||||
if (argv[0] === '--') {
|
||||
files.push(...argv.slice(1));
|
||||
break;
|
||||
}
|
||||
arg = getArg();
|
||||
switch (arg) {
|
||||
case '-o':
|
||||
|
||||
@@ -29,6 +29,9 @@ marked --output="hello world.html" -i in.md --no-breaks
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* --
|
||||
End option parsing. Arguments after this are treated as input filenames, even if they start with a hyphen.
|
||||
|
||||
* -o, --output [output file]
|
||||
Specify file output. If none is specified, write to stdout.
|
||||
|
||||
|
||||
@@ -304,6 +304,29 @@ describe('bin/marked', () => {
|
||||
});
|
||||
|
||||
describe('input', () => {
|
||||
it('does not treat --=value as the end of options', testInput({
|
||||
args: ['--=ignored', '--string', '# test'],
|
||||
stdout: '<h1>test</h1>',
|
||||
}));
|
||||
|
||||
for (const filename of ['-s.md', '--version']) {
|
||||
it(`treats ${filename} as a filename after --`, async() => {
|
||||
const dir = await mkdtemp(resolve(tmpdir(), 'marked-end-options-'));
|
||||
try {
|
||||
await writeFile(resolve(dir, filename), '~~file contents~~');
|
||||
const { stdout, stderr } = await execFileAsync(process.execPath, [
|
||||
resolve(import.meta.dirname, '../../bin/marked.js'),
|
||||
'--no-gfm', '--', filename,
|
||||
], { cwd: dir });
|
||||
|
||||
assert.strictEqual(stdout, '<p>~~file contents~~</p>\n\n');
|
||||
assert.strictEqual(stderr, '');
|
||||
} finally {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it('input file positional', testInput({
|
||||
args: [fixturePath('bin-input.md')],
|
||||
stdout: '<h1>file</h1>',
|
||||
|
||||
Reference in New Issue
Block a user