pietroppeter / nimib

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

nbHtml #28

Open pietroppeter opened 3 years ago

pietroppeter commented 3 years ago

a new nbHtml block that will expose karax htmldsl and allow to render the html in the document.

ajusa commented 3 years ago

To add onto this request, would it be possible to have that block also handle js compiling somehow? This may not even be possible (some of the file is compiled to C, and the rest is compiled to JS?) but I figured I would ask. The use case that I have in mind was to trying using nimib to write documentation for Karax. Ideally, I would be able to have a block that would correspond to an example written in Karax.

pietroppeter commented 3 years ago

this feature is specifically to introduce an html dsl (and thinking of using the server side part of karax).

I like your suggestion and I think it should be added, possibly with a different API (nbFile and nbShell). I created a new issue for this: #34 (this api was also mentioned in #2).

Open to suggestion on the api (and also PR for implementation :)).

HugoGranstrom commented 2 years ago

I will add this here as I think it fits under the general nbHTML context but perhaps not totally relevant for the karax dsl part.

When implementing nimib-reveal I have abused nbText like this:

nbText: """<div class="fragment fade-out">"""
body
nbText: """</div>"""

to insert HTML code directly into the document. This works most of the time except when it doesn't, it depends on what tags nim-markdown chooses to take into consideration. Replacing div with span doesn't work for example as the closing tag gets enclosed in <p></span></p>. The situation where it really has tripped me up though is when I need to use mustache variables {{ variable }} in my HTML code. The reason for this is that I can only get the value of the variable after the body has run, but must create it before it has run. As nbText isn't rendered for replacements in nb.context I currently have to have my own modified versions of the rendering procs in nimib that runs render on the text: link to code.

So to sum up, a feature where we can input raw HTML (as a string primarily, but could in addition to that be a DSL as well) and which runs through render would be a needed feature for really opening up the world of making crazy stuff with nimib 😄

It should be noted I hadn't realized this was even possible until I saw the source for your paranimib repo and how you inserted the audio player using HTML 😃

pietroppeter commented 2 years ago

Yes, I started abusing nbText that way and it is not the way forward. I really need to finish up the block render refactoring which will allow all this (each block will have its own context and a partial among other things)

HugoGranstrom commented 2 years ago

Oh, that sounds nice! 🚀 I'm a bit scared of having to refactor everything though 🤣

pietroppeter commented 2 years ago

If I get it right it will be easy, I actually plan to start from refactoring all block the way I want them (possibly including neveal's ones) and then implementing the new rendering engine. Will try this afternoon.

HugoGranstrom commented 2 years ago

That would be great! I re-read the description in the rendering issue and it sounds like it would satisfy my needs. Making reuse of other blocks' logic (nbCode and nbText in particular) would make it really powerful. Once I'm done with the fragments I will add a custom nbCode block feature with code animations, and being able to reuse the nbCode logic while storing all local parameters in a local context and inserting them later would be really convenient. Should stop now before I start asking for impossible things 🤭 (we can continue discussions in the correct issue if there are anything we want to discuss)

pietroppeter commented 2 years ago

see api examples added here https://github.com/pietroppeter/nimib/issues/24#issuecomment-993839452

will add more

pietroppeter commented 2 years ago

with #80 we added nbRawOutput that can be used to generate an escaped output and in particular often used for html output.

with #88 we added nbKarax where inside one can use nbKaraxHtml template to generate html using Karax dsl.

The feature described here is still distinct from the above so I will keep this open.