Skip to content

Feature Request: render IPython/Jupyter Notebooks in repo view pane #2877

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

Closed
2 of 7 tasks
minoru7 opened this issue Nov 9, 2017 · 16 comments
Closed
2 of 7 tasks

Feature Request: render IPython/Jupyter Notebooks in repo view pane #2877

minoru7 opened this issue Nov 9, 2017 · 16 comments
Labels
issue/duplicate The issue has already been reported.

Comments

@minoru7
Copy link

minoru7 commented Nov 9, 2017

  • Gitea version (or commit ref): latest
  • Git version: 2.1.4
  • Operating system: Linux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I would like to request that a feature be added to render IPython/Jupyter Notebooks in the file view of a repo.

Gogs (and GitLab/GitHub, etc.) have the ability to view IPython/Jupyter Notebooks in rendered form, but also to pull it up in source/raw, however in Gitea they are displayed as text only. Gogs uses notebook.js and marked.js to do this work. Gogs has the plugins in "public/plugins". There are some modifications in "pkg/markup/markup.go", "routes/repo/view.go", "templates/repo/view_file.tmpl", and "templates/base/head.tmpl".

I believe the locations in Gitea would be the following: "modules/markup/markup.go", "routers/repo/view.go", "public/vendor/plugins", "templates/base/head.tmpl", and "templates/repo/view_file.tmpl".

An example of the end goal is given in the screenshots below.

Screenshots

Current View:
ipythonnotebook_currentgiteaview

This is what it should look like (this is from GitLab):
gitlab_edited

@lunny
Copy link
Member

lunny commented Nov 10, 2017

Please see #2570

@lunny lunny closed this as completed Nov 10, 2017
@lunny lunny added the issue/duplicate The issue has already been reported. label Nov 10, 2017
@entron
Copy link

entron commented Jan 4, 2018

Could somebody explain how to enable this feature? I can't find it anywhere.

@lunny
Copy link
Member

lunny commented Jan 5, 2018

see #3301

@entron
Copy link

entron commented Jan 6, 2018

@lunny, sorry I still couldn't figure out how to do it. Is there a more detailed instruction specifically for ipython notebook?

@eapetitfils
Copy link

@entron Just adding it here as I guess people will come back to this issue if they want to know how to do it.

Let's say you have access to the server running gitea, and you can install python on it. Create a virtual environment and install jupyter in it. What you need to add in the config file to render jupyter notebooks is the following:

[markup.jupyter]
ENABLED = true
FILE_EXTENSIONS = .ipynb
RENDER_COMMAND = "<path to virtual environment>/bin/jupyter nbconvert --stdout --to html --template basic "
IS_INPUT_FILE = true

You obviously need to give exec access for the virtual environment to your web server user.

I am still not fully happy with this solution as the python code is not coloured. But that is a huge step forward when compared to the json text displayed before.

The --to html --template basic is not technically needed, though it gives smaller HTML content. I could not see a difference in the output.

@entron
Copy link

entron commented Oct 25, 2018

@eapetitfils Thank you very much for this instruction. I followed it but I got an empty output when I opened a jupyter file in gitea. Could you tell me how to debug it? I want to find the error log but I don't know where to find it.

@typeless
Copy link
Contributor

@entron the log files reside in the log subdirectory of your Gitea installation. If you start Gitea with systemd, you can use sudo journalctl -u gitea to view the console log, which could be more helpful than the log files.

If you run Gitea in docker, try docker logs . I don't install Gitea with docker, so I am not sure about how it looks.

@choucavalier
Copy link

choucavalier commented Oct 25, 2018

Side-note: sudo journalctl -u gitea -n 200 -f will

  1. show only the last 200 lines of logs (-n 200),
  2. and print/stream the logs as they come to stdout (-f), mimicking the tail -f behaviour.

@eapetitfils
Copy link

@entron what version of gitea are you using?

Have you tried running the render command outside of gitea? It should print out all the HTML code.

And do not forget the space at the end of the render command in your config file.

@entron
Copy link

entron commented Oct 25, 2018

Thanks you all for the help! I realized the reason: I was running gitea in docker and I installed jupyter only on the host:) I installed jupyter inside the gitea docker container with:

apk --no-cache add gcc g++ python3-dev py3-pip
pip3 install jupyter

@entron
Copy link

entron commented Oct 25, 2018

After I installed jupyter in the docker the notebook rendering worked except images did not show up. I have checked the output of the command as suggested by @eapetitfils, the html output did contain the image. I am using the latest version. Does anyone have the same issue as me?

@eapetitfils
Copy link

eapetitfils commented Nov 13, 2018

Maybe a way to do it would be to add the handling of data URI images in the sanitizer policy: p.AllowDataURIImages().

However, this comes with a security risk so not sure if this is a good idea to have that enabled all the time. And even if this was enabled only for specific external renderers, I am not sure nbconvert protects against a malicious ipynb file.

There is also the colour rendering that is nuked by the sanitizer.

Edit:
Looking at the security risk, I do not believe it applies here. p.AllowDataURIImages() only allows GIF, JPEG, PNG and WEBP data URI, and the security risk is about HTML. I tried to reproduce the security risk above by manipulating the base64 part of the image URI without success.

What's left after this is embedding code inside a PNG, but AFAIK that is harmless until activated by something else and, anyway, could be embedded in any image hosted on Gitea, so this is not relevant to external parser.

@wbadart
Copy link

wbadart commented Feb 15, 2019

Let's say you have access to the server running gitea, and you can install python on it. Create a virtual environment and install jupyter in it. What you need to add in the config file to render jupyter notebooks is the following:
...

@eapetitfils sorry for the n00b question: which config file do we add this to?

@eapetitfils
Copy link

To the gitea app.ini config file, which path depends on how gitea was installed (typically in /etc/gitea/conf/app.ini).

More details were added lately to the documentation: https://docs.gitea.io/en-us/external-renderers/

@wbadart
Copy link

wbadart commented Feb 15, 2019

Awesome. Many thanks!

@gbrault
Copy link

gbrault commented Aug 26, 2019

@eapetitfils said:

Maybe a way to do it would be to add the handling of data URI images in the sanitizer policy: p.AllowDataURIImages().

where do we set this p.AllowDataURIImages()?

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/duplicate The issue has already been reported.
Projects
None yet
Development

No branches or pull requests

8 participants