[x]
):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.
Current View:
This is what it should look like (this is from GitLab):
Please see https://github.com/go-gitea/gitea/pull/2570
Could somebody explain how to enable this feature? I can't find it anywhere.
@lunny, sorry I still couldn't figure out how to do it. Is there a more detailed instruction specifically for ipython notebook?
@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 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 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.
Side-note: sudo journalctl -u gitea -n 200 -f
will
-n 200
),-f
), mimicking the tail -f
behaviour.@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.
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
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?
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.
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?
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/
Awesome. Many thanks!
@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()?
Most helpful comment
@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:
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.