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

Closed
opened 2025-11-02 03:52:59 -06:00 by GiteaMirror · 16 comments
Owner

Originally created by @minoru7 on GitHub (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

Originally created by @minoru7 on GitHub (Nov 9, 2017). - Gitea version (or commit ref): latest - Git version: 2.1.4 - Operating system: Linux - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] 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](https://user-images.githubusercontent.com/11465939/32616428-54b63ddc-c540-11e7-9577-23e60f0a30f8.png) This is what it should look like (this is from GitLab): ![gitlab_edited](https://user-images.githubusercontent.com/11465939/32626012-0c4606d8-c55c-11e7-82cb-53f40aecd1b5.png)
GiteaMirror added the issue/duplicate label 2025-11-02 03:52:59 -06:00
Author
Owner

@lunny commented on GitHub (Nov 10, 2017):

Please see https://github.com/go-gitea/gitea/pull/2570

@lunny commented on GitHub (Nov 10, 2017): Please see https://github.com/go-gitea/gitea/pull/2570
Author
Owner

@entron commented on GitHub (Jan 4, 2018):

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

@entron commented on GitHub (Jan 4, 2018): Could somebody explain how to enable this feature? I can't find it anywhere.
Author
Owner

@lunny commented on GitHub (Jan 5, 2018):

see https://github.com/go-gitea/gitea/pull/3301

@lunny commented on GitHub (Jan 5, 2018): see https://github.com/go-gitea/gitea/pull/3301
Author
Owner

@entron commented on GitHub (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?

@entron commented on GitHub (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?
Author
Owner

@eapetitfils commented on GitHub (Oct 17, 2018):

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

@eapetitfils commented on GitHub (Oct 17, 2018): @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.
Author
Owner

@entron commented on GitHub (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.

@entron commented on GitHub (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.
Author
Owner

@typeless commented on GitHub (Oct 25, 2018):

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

@typeless commented on GitHub (Oct 25, 2018): @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.
Author
Owner

@choucavalier commented on GitHub (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.
@choucavalier commented on GitHub (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.
Author
Owner

@eapetitfils commented on GitHub (Oct 25, 2018):

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

@eapetitfils commented on GitHub (Oct 25, 2018): @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.
Author
Owner

@entron commented on GitHub (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 commented on GitHub (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 ```
Author
Owner

@entron commented on GitHub (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?

@entron commented on GitHub (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?
Author
Owner

@eapetitfils commented on GitHub (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.

@eapetitfils commented on GitHub (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](https://capec.mitre.org/data/definitions/244.html) 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.
Author
Owner

@wbadart commented on GitHub (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?

@wbadart commented on GitHub (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?
Author
Owner

@eapetitfils commented on GitHub (Feb 15, 2019):

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/

@eapetitfils commented on GitHub (Feb 15, 2019): 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/
Author
Owner

@wbadart commented on GitHub (Feb 15, 2019):

Awesome. Many thanks!

@wbadart commented on GitHub (Feb 15, 2019): Awesome. Many thanks!
Author
Owner

@gbrault commented on GitHub (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()?

@gbrault commented on GitHub (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()?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#1226