Am I correct to assume that this is because the contents of the markdown cell ‘break’ the JSON because of some characters that ought to be escaped? Is there a way I can achieve this sort of manual JSON object creation into which I import from a markdown cell without too much fuss?
Not quite. Your object contains a DOM element that cannot be serialized. If you want the cell content to be downloadable as JSON, you’ll have to reference your rendered markdown like this:
{
// ...
content: intro_within_md.outerHTML,
}
When you open a cell menu, Observable will query the cell’s download type from the worker. Inside the worker script is some proprietary code that attempts to determine the data type. For objects it will iterate over all properties (up to a limit) and check each property value. You can search for “downloadType” in your dev tools to find the relevant sources.
Thanks @mootari! As usual, you’re clear explanations help a lot.
Just for my deeper understanding: All observable cells using template literals are converted into DOM elements, and to use them correctly in a JSON object, I have to specify which of those DOM elements I wish to select and print.
You’ve pointed me to .outerHTML twice this week. I’ll clearly need to read up more on these elements and to better learn how to read cell output (not only when it’s printed back into a notebook).
No, basic template literals will only return a string. But when you tag a template literal, then the tagged template literal will return whatever the tag function returns.
When you use one of the tag functions from Observable’s stdlib (html, md, svg, tex), then those tagged template literals will return the DOM element (and DOM tree) that has been created by the respective tag function.