Closed pietroppeter closed 1 year ago
Ah right, I opted for not using codeAsInSource for nbJs because of the composability issues. But using it just for the code shown by nbJsShowSource
could work. How does that sound like?
yep, that sounds fine!
Hmm thinking a bit more about it, I don't think we should do this actually. If the nbJs block is defined in another file, codeAsInSource will not be able to locate it and error, which is bad. The error is because codeAsInSource only looks in the current file. The problem is that the current way we are doing this is to mark the block as showSource
after it has been created. Hence we would have to run the codeAsInSource for every single nbJs block because the user may want to show it. Do you see the problem?
So the solution imo is to just do a nimibCode
with the nbJsFromCode
instead if you really care about formatting:
nimibCode:
nbJsFromCode:
# Comment
echo "Hello world"
# vs
nbJsFromCode:
# Comment
echo "Hello world"
nbJsShowSource()
yeah, I guess you are right, it complicates stuff too much. So, now I am thinking, should we remove (with a deprecation period) nbJsShowSource
? I am having trouble thinking what is the problem it tries to solve... (not showing code, since it is suboptimal for it). I am looking at the source and it complicates a lot of stuff (we support the message, we have special support for rendering...). we did not have nimibCode
before, but now we do...
I agree, nimibCode
makes nbJsShowSource
deprecated. There's no hurry to get this done, we just have to remember to include this in the next release.
mmh, in p5nim I am not sure I want to use nimibCode
since it would add the additional noise of showing nbJsFromCode
and an additional layer of indentation. I was thinking of adding an additional nbJsFromCodeDisplay
(or another name if we find a better one) maybe like this:
template nbJsFromCodeDisplay*(args: varargs[untyped]):
newNbCodeBlock("nbJsFromCodeDisplay", args[^1]):
discard
nbJsFromCode(args)
I would then need to add partials and renderPlan as in nbCode.
Yeah, if we are going to support it, this seems like the easiest way 👍
an even easier way that generalizes to other templates (restricted to template with single body argument, but you should always be able to wrap a more complex template in one with a single body argument) implement with nbCodeDisplay in #158
I am using
nbJsShowSource
for showing p5js examples (see e.g. https://pietroppeter.github.io/nim-p5/polygons.html). The code comes from ast instead of being read from source, with all classical problems (no comments and weird indents).