observablehq / inspector

The Observable standard inspector.
ISC License
143 stars 20 forks source link

Inconsistent string formatting #177

Closed mootari closed 3 years ago

mootari commented 3 years ago

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"})]
mbostock commented 3 years ago

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.