Skip to content

Commit

Permalink
Exclude nested properties in md output mode. Closes #4241
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodecleyre authored and martinlingstuyl committed Apr 5, 2023
1 parent 20be5df commit 600b4c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ describe('Command', () => {
assert(actual.indexOf('\\_\\*\\~\\`\\|') > -1);
});

it('serializes objects that are values to JSON', () => {
it('excludes objects in md output', () => {
const command = new MockCommand1();
const commandOutput = [
{
Expand All @@ -519,7 +519,7 @@ describe('Command', () => {
}
];
const actual = command.getMdOutput(commandOutput, command, { options: { output: 'md' } });
assert(actual.indexOf(JSON.stringify(commandOutput[0].property)) > -1);
assert(actual.indexOf(JSON.stringify(commandOutput[0].property)) === -1);
});

it('excludes objects that are values to JSON', () => {
Expand Down
14 changes: 8 additions & 6 deletions src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,16 @@ export default abstract class Command {
`Property | Value`, os.EOL,
`---------|-------`, os.EOL
);
output.push(Object.keys(l).map(k => {
const value = l[k];
let stringValue = value;
if (typeof value === 'object') {
stringValue = JSON.stringify(value);
output.push(Object.keys(l).filter(x => {
if (!options.query && typeof l[x] === 'object') {
return;
}

return `${md.escapeMd(k)} | ${md.escapeMd(stringValue)}`;
return x;
}).map(k => {
const value = l[k];

return `${md.escapeMd(k)} | ${md.escapeMd(value)}`;
}).join(os.EOL), os.EOL);
output.push(os.EOL);
});
Expand Down

0 comments on commit 600b4c0

Please sign in to comment.