Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code shown with nbJsShowSource is not as in source (but comes from ast) #154

Closed
pietroppeter opened this issue Nov 14, 2022 · 8 comments · Fixed by #158
Closed

Code shown with nbJsShowSource is not as in source (but comes from ast) #154

pietroppeter opened this issue Nov 14, 2022 · 8 comments · Fixed by #158

Comments

@pietroppeter
Copy link
Owner

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).

@HugoGranstrom
Copy link
Collaborator

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?

@pietroppeter
Copy link
Owner Author

yep, that sounds fine!

@HugoGranstrom
Copy link
Collaborator

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()

@pietroppeter
Copy link
Owner Author

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...

@HugoGranstrom
Copy link
Collaborator

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.

@pietroppeter
Copy link
Owner Author

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.

@HugoGranstrom
Copy link
Collaborator

Yeah, if we are going to support it, this seems like the easiest way 👍

@pietroppeter
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants