Open Kiloneie opened 3 months ago
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.
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.
another option is to just use a nbText
codeblock with the non parsable nim code:
nbText: """
blabla
```nim
nbCodeSkip:
if 1 == 1:
```
"""
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 ?