observablehq / inspector

The Observable standard inspector.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent string formatting

mootari opened this issue · comments

Strings in property values and arrays are wrapped in double quotes, while strings directly passed to the inspector are wrapped in backticks. This causes different outputs:

// Output: `{"foo":"bar"}`
JSON.stringify({"foo": "bar"})
// Output: Array(1) ["{\"foo\":\"bar\"}"]
[JSON.stringify({"foo": "bar"})]

The inspector has different behavior when the value is top-level vs. as a descendent. This can be seen here:

https://github.com/observablehq/inspector/blob/main/src/formatString.js

When a string is top-level, the inspector applies an optimization to minimize the number of escaping characters depending on the contents of the string. The inspector will also render a “show more” button for strings with many new lines.

And when a string is not top-level, the inspector will also truncate the string to limit its length to the first and last 50 characters.