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

nbCodeSkip requires at least 1 statement per scope/conditional #236

Open
Kiloneie opened this issue Mar 14, 2024 · 3 comments
Open

nbCodeSkip requires at least 1 statement per scope/conditional #236

Kiloneie opened this issue Mar 14, 2024 · 3 comments

Comments

@Kiloneie
Copy link

Is this the intended functionality ? I don't understand why the nbCodeSkip checks the code at all, since it's supposed to just show the code, and not do any kind of checking if it's parsable. In other words, it skips all the errors etc, but not any opened empty scopes.

Example:
nbCodeSkip:
if 1 == 1:

It's not that big of a deal, but it prevents splitting a block of code by lines for explanations.
My current 2x solutions are putting a discard in the body, but that is then visible to the viewer,
and option 2x is to use a custom block e.g. repurposing nbPython into nbCodeSnippet with Nim's highlighting.

template nbCodeSnippet(body: untyped) =
newNbCodeBlock("nbCodeSnippet", body):
nb.blk.output = body

nb.partials["nbCodeSnippet"] = """<pre><code class="hlNim">{{&output}}</code></pre>"""
nb.renderPlans["nbCodeSnippet"] = @["highlightCode"]

Thoughts ?

@HugoGranstrom
Copy link
Collaborator

This is a limitation of the compiler. An untyped block doesn't have to be valid Nim code, but it must be parseable by the compiler. And the code you sent simply isn't parseable by the compiler I would assume.

@HugoGranstrom
Copy link
Collaborator

What you have done is probably the way to go (take a string as input). Or maybe create a block that takes the entire block as input at first, and then you can choose which lines to show later on.

@pietroppeter
Copy link
Owner

another option is to just use a nbTextcodeblock with the non parsable nim code:

nbText: """
blabla
```nim
nbCodeSkip:
  if 1 == 1:
```
"""

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

No branches or pull requests

3 participants