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

{% filter solution %} for Jupyter notebooks #13

Open
frenzymadness opened this issue Oct 16, 2019 · 5 comments
Open

{% filter solution %} for Jupyter notebooks #13

frenzymadness opened this issue Oct 16, 2019 · 5 comments

Comments

@frenzymadness
Copy link
Member

It'd be nice to have a possibility to hide solutions by {% filter solution %} also in Jupyter notebooks.

@encukou
Copy link
Member

encukou commented Oct 16, 2019

Maybe it would be easier to hide cells based on cell metadata. Would that work for you as well?

@frenzymadness
Copy link
Member Author

Yes, sure, whatever is easier to implement. I just don't know how does the machinery translating notebook to HTML works here. It would be nice if it would look the same as in MD/HTML and also with "uncover the solution" functionality.

@hroncok
Copy link
Member

hroncok commented Oct 16, 2019

This is the way we render Notebooks:

https://github.com/pyvec/naucse_render/blob/master/naucse_render/notebook.py

@frenzymadness
Copy link
Member Author

I dive deeper a little bit and now I understand how I can adjust nbconvert templates. But what I don't know yet is how I can combine it all together. It seems that adding the right class to some div element is not enough because the solution filter is much more complicated.

I can imagine that a simple modification of nbconvert template would add a {% filter solution %} around a cell content based on a cell metadata/tags. But then, the resulting HTML would have to be processed once more with Jinja.

Is there a simple way how to process a result of nbconvert NaucseHTMLExporter with Jinja? nbconvert uses Jinja internally so it might be possible to just register a template filter and let nbconvert to handle it.

@encukou
Copy link
Member

encukou commented Nov 13, 2019

There are three divs, see https://github.com/pyvec/naucse_render/blob/master/naucse_render/templates.py#L48

A quick temporary solution would be to avoid putting stuff in ctx['$solutions'], and omitting the link to solution_url. The downside is that you then need Javascript to see the solution.

@encukou encukou transferred this issue from pyvec/naucse Nov 25, 2019
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