pietroppeter / nimib

nimib 🐳 - nim 👑 driven ⛵ publishing ✍
https://pietroppeter.github.io/nimib/
MIT License
175 stars 10 forks source link

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

Open Kiloneie opened 3 months ago

Kiloneie commented 3 months ago

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

HugoGranstrom commented 3 months ago

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 commented 3 months ago

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

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