Skip to content

Commit e92bb5e

Browse files
authored
Merge pull request #328 from knightspore/fix-argument-converter-json-formatting-indentation
Fix ArgumentConverter JSON Formatting Indendation Bug
2 parents c51995d + e968095 commit e92bb5e

4 files changed

Lines changed: 546 additions & 535 deletions

File tree

src/ArgumentConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ArgumentConverter {
3131
}
3232

3333
public static prettyFormatForHtml(arg: any): string {
34-
const formatted = prettyFormat(arg, { indent: ' ' } as any)
34+
const formatted = prettyFormat(arg, { indent: 4 })
3535
// format whitespace for display in html
3636
.replaceAll(' ', ' ')
3737
.replace(/\r\n|\r|\n/g, '<br>')

tests/ArgumentConverter.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ it('convert to primitive with a null argument', () => {
3434
expect(result.value).toBeNull();
3535
expect(result.isHtml).toBe(false);
3636
});
37+
38+
// Tests that convertToPrimitive returns string value and isHtml property is true when an object or array argument is passed
39+
it('converts array with decimal numbers to html correctly', () => {
40+
const arg = ['foo', 'bar', 123, 0.123, { A: 123 }, null];
41+
const result = ArgumentConverter.convertToPrimitive(arg);
42+
43+
expect(result.value).toBe(
44+
'<code style="font-size: 0.8rem!important;" class=""><code style="font-size: 0.8rem!important;" class="bold text-gray-500 p-0">&nbsp;<span style="font-size: 0.8rem!important;" class="bold text-orange-400">[</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<code style="font-size: 0.8rem!important;" class="bold text-green-600 p-0">"foo"</code><span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<code style="font-size: 0.8rem!important;" class="bold text-green-600 p-0">"bar"</code><span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;123<span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;0.123<span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 0.8rem!important;" class="bold text-yellow-600">Object</span>&nbsp;<code style="font-size: 0.8rem!important;" class="text-gray-600"><span style="font-size: 0.8rem!important;" class="bold text-orange-400">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code style="font-size: 0.8rem!important;" class="bold text-green-600 p-0">"A"</code><span style="font-size: 0.8rem!important;" class="bold text-orange-400">:&nbsp;</span>123<span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 0.8rem!important;" class="bold text-orange-400">}</span></code><span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 0.8rem!important;" class="bold text-indigo-600">null</span><span style="font-size: 0.8rem!important;" class="bold text-orange-400">,</span><br><span style="font-size: 0.8rem!important;" class="bold text-orange-400">]</span></code></code>',
45+
);
46+
expect(result.isHtml).toBe(true);
47+
});

0 commit comments

Comments
 (0)