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

JSON formatting is broken #10

Open
cowboy opened this issue Oct 1, 2021 · 0 comments
Open

JSON formatting is broken #10

cowboy opened this issue Oct 1, 2021 · 0 comments

Comments

@cowboy
Copy link

cowboy commented Oct 1, 2021

If I do this:

console.log(endent`
      hello

      \`\`\`json
      ${endent.pretty({ a: 1, b: 2, c: { foo: 3, bar: 4 } })}
      \`\`\`
      
      world
`)

Or this:

const myJson = JSON.stringify({ a: 1, b: 2, c: { foo: 3, bar: 4 } })
console.log(endent`
      hello

      \`\`\`json
      ${myJson}
      \`\`\`
      
      world
`)

I get this poorly-formatted output:

hello

    ```json
    {
"a": 1,
"b": 2,
"c": {
  "foo": 3,
  "bar": 4
}
}
    ```

    world

But I expect this:

hello

```json
{
  "a": 1,
  "b": 2,
  "c": {
    "foo": 3,
    "bar": 4
  }
}
```

world

However, if I put some text before my object:

console.log(endent`
      hello

      \`\`\`json
      REMOVE_ME${endent.pretty({ a: 1, b: 2, c: { foo: 3, bar: 4 } })}
      \`\`\`
      
      world
`)

It formats everything correctly (but then I need to remove the REMOVE_ME bit in a separate step):

hello

```json
REMOVE_ME{
  "a": 1,
  "b": 2,
  "c": {
    "foo": 3,
    "bar": 4
  }
}
```

world

I was going to file this over at https://github.com/zhouhanseng/endent but you have issues disabled there.

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