Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: double-encoding for manifestJsonEx examples #1205

Open
adam-azarchs opened this issue Jan 23, 2025 · 0 comments
Open

docs: double-encoding for manifestJsonEx examples #1205

adam-azarchs opened this issue Jan 23, 2025 · 0 comments

Comments

@adam-azarchs
Copy link

The stdlib documentation for manifestJson, manifestJsonMinified, and manifestJsonEx use the same formatting logic as other functions with examples,

html.spaceless([html.code({}, ex.input), ' yields ', html.code({}, manifestJsonSingleLine(ex.output))])

which passes the result through
local manifestJsonSingleLine(val) = std.strReplace(std.manifestJsonEx(val, ''), '\n', ' ');

Specifically for these functions, this seriously obfuscates the results, e.g.

examples: [
{
input: |||
std.manifestJsonEx(
{
x: [1, 2, 3, true, false, null,
"string\nstring"],
y: { a: 1, b: 2, c: [1, 2] },
}, " ")
|||,
output:
std.manifestJsonEx(
{
x: [
1,
2,
3,
true,
false,
null,
'string\nstring',
],
y: { a: 1, b: 2, c: [1, 2] },
}, ' '
),
},

renders as

Example: std.manifestJsonEx( { x: [1, 2, 3, true, false, null, "string\nstring"], y: { a: 1, b: 2, c: [1, 2] }, }, " ") yields "{\n \"x\": [\n 1,\n 2,\n 3,\n true,\n false,\n null,\n \"string\\nstring\"\n ],\n \"y\": {\n \"a\": 1,\n \"b\": 2,\n \"c\": [\n 1,\n 2\n ]\n }\n}".

It should really not be stripping the repeaded whitespaces from the example input, and it should be rendering the output as

{
    "x": [
        1,
        2,
        3,
        true,
        false,
        null,
        "string\nstring"
    ],
    "y": {
        "a": 1,
        "b": 2,
        "c": [
            1,
            2
        ]
    }
}

more similarly to the documentation for the other manifest* functions, e.g.

html.pre({}, |||
std.manifestYamlDoc(
{
x: [1, 2, 3, true, false, null,
"string\nstring\n"],
y: { a: 1, b: 2, c: [1, 2] },
},
indent_array_in_object=false)
|||),
html.p({}, |||
Yields a string containing this YAML:
|||),
html.pre({}, |||
"x":
- 1
- 2
- 3
- true
- false
- null
- |
string
string
"y":
"a": 1
"b": 2
"c":
- 1
- 2
|||),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant