E.g. to create some generic documentation, I’d like call a function with a cell reference as argument and then generate some md that includes the cell’s name.
Also, this is not officially supported, but recently I put together notebooks.js notebook that shows you how to use observable api directly for getting user bio, notebooks info, and notebook cells. see Getting Notebook Info and #notebookNodes section here:
Every notebook on observable is stored/returned in this json format:
Even though nodes don’t break cell names and code blocks into separate properties, I think you can easily parse out named cells names from the code node value by index of = and ( for functions
Do you intend to have this notebook documentation system outside of the hosted notebook itself? If so that might help.
I am curious how you auto-generate cell’s description. Are you thinking along the lines of creating spec. js for each notebook you create?
Sorry, that is not what I need. I don’t need png or svg to download. I’m just a guy who exhausts himself in laziness and want Greyhound to do the driving. If I type in the name of an object, there must be some way to get that name (as a string), right?
Never mind. It works for now, so yes, we’re done.
Thanks very much for your effort and brain cycles.
How about the following? I hacked this together from this SO answer which explains how it works:
function howToImport2(logoDict) {
function getVariableName(unknownVariable) {
return Object.keys(unknownVariable)[0];
};
const logo = logoDict[getVariableName(logoDict)];
let d = gcd(logo.width, logo.height);
return md`\`import {${getVariableName(logoDict)}} from "@martien/creative-commons-logos"
(${logo.width}:${logo.height} (${logo.width / d}:${logo.height / d}))\``;
}
To use howtoimport2, note that you have to do the slightly odd thing of wrapping the argument in curly braces like this: