Skip to content
2 changes: 1 addition & 1 deletion src/ArgumentConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ArgumentConverter {
}

public static prettyFormatForHtml(arg: any): string {
const formatted = prettyFormat(arg, { indent: ' ' } as any)
const formatted = prettyFormat(arg, { indent: 4 })
// format whitespace for display in html
.replaceAll(' ', ' ')
.replace(/\r\n|\r|\n/g, '<br>')
Expand Down
11 changes: 11 additions & 0 deletions tests/ArgumentConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ it('convert to primitive with a null argument', () => {
expect(result.value).toBeNull();
expect(result.isHtml).toBe(false);
});

// Tests that convertToPrimitive returns string value and isHtml property is true when an object or array argument is passed
it('converts array with decimal numbers to html correctly', () => {
const arg = ['foo', 'bar', 123, 0.123, { A: 123 }, null];
const result = ArgumentConverter.convertToPrimitive(arg);

expect(result.value).toBe(
'<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>',
);
expect(result.isHtml).toBe(true);
});
Loading
Loading