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

External markup renderer doesn't show any embedded images #3025

Closed
2 of 7 tasks
kzfm opened this issue Nov 29, 2017 · 23 comments
Closed
2 of 7 tasks

External markup renderer doesn't show any embedded images #3025

kzfm opened this issue Nov 29, 2017 · 23 comments
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug

Comments

@kzfm
Copy link

kzfm commented Nov 29, 2017

  • Gitea version (or commit ref): 1.3
  • Git version: Not relevant
  • Operating system: Not relevant
  • 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 added some option into my app.ini.

[markup.ipynb]
ENABLED = true
FILE_EXTENSIONS = .ipynb
RENDER_COMMAND ="jupyter nbconvert --stdin --stdout --to html"
IS_INPUT_FILE = false

Now, converting from ipynb to html works, but it doesn’t show any embedded images.

my jupyter notebook example code is here.

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y);

...

Screenshots

@lunny
Copy link
Member

lunny commented Nov 29, 2017

Any repository example on github?

@kzfm
Copy link
Author

kzfm commented Nov 29, 2017

I created a repo.

@lunny lunny added the type/bug label Nov 29, 2017
@lunny
Copy link
Member

lunny commented Nov 29, 2017

Some tags maybe has been removed for safety.

@lunny lunny added this to the 1.4.0 milestone Nov 29, 2017
@lunny
Copy link
Member

lunny commented Dec 2, 2017

This is because the render generated <html> tag but gitea will ignore that and sub tags.

@memetb
Copy link

memetb commented Jan 1, 2018

I'm not clear why there's a need to use jupyter at all. gogs is able to preview these files just fine without having to re-render them (which can be unsafe and time costly). Is there a reason why this feature was lost?

@ivoszz
Copy link

ivoszz commented Apr 23, 2018

Same problem for asciidoc. The rendered path for images has the form "https://name.domain/user/repo/src/branch/master/file.png instead of correct "https://name.domain/user/repo/raw/branch/master/file.png.

@lunny
Copy link
Member

lunny commented Apr 29, 2018

@ivoszz your issue is different from this one, maybe you could fire another one.

@techknowlogick techknowlogick modified the milestones: 1.5.0, 1.6.0 May 25, 2018
@lafriks lafriks modified the milestones: 1.6.0, 1.7.0 Sep 16, 2018
@pavilo
Copy link

pavilo commented Nov 23, 2018

It looks like the root cause for this is in the sanitizer. It removes a lot of things, such as inline (incl scoped) CSS, images with data URIs, iframes etc. Is it possible to add an external sanitization configuration per markup handler?
To make something meaningful our of the external markup renderer one may have to use things like scoped CSS, images (both data URI and links to raw project resources) and unfortunately sometimes also javascript (e.g. MathJax, jupyter widgets etc). In extreme cases an iframe may be required too.

This configuration mostly works for a jupyter notebook with python code and embedded images:

sanitizer.policy.AllowImages()
sanitizer.policy.AllowDataURIImages()
sanitizer.policy.AllowLists()
sanitizer.policy.AllowTables()
sanitizer.policy.AllowAttrs("class").Globally() // may targeted at concrete elements e.g. div, span, a, h1 ...
sanitizer.policy.AllowAttrs("type", "scoped").OnElements("style")

@bekker
Copy link

bekker commented Nov 28, 2018

I'm not sure it's exactly the same issue, but <img> tags with relative image path in .md files needs to be switched to 'raw' path, like github and gogs handle them.

2018-11-28 12 38 54

@lafriks lafriks modified the milestones: 1.7.0, 1.8.0 Dec 27, 2018
@techknowlogick techknowlogick modified the milestones: 1.8.0, 1.9.0 Feb 19, 2019
@programagor
Copy link

@pavilo Does that mean that I'd need to recompile Gitea with the modified sanitizer.go in order to display Jupyter notebooks? Is it possible to expose these settings in app.ini instead?

@Tdarnell
Copy link

I have also run into this issue and would second disabling certain sanitiser settings in the markdown.jupyter section of app.ini

@pavilo
Copy link

pavilo commented Feb 23, 2019

@programagor - yes, recompilation may be needed. Moreover, I only tested this config as a standalone golang executable, to make sure that the jupyter page renders as expected. The integration into gitea may require additional modifications.

@stale
Copy link

stale bot commented Apr 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale stale bot added the issue/stale label Apr 24, 2019
@worthy7
Copy link

worthy7 commented Apr 25, 2019

Hi, This is a problem. I created images in my markdown file like this :

![vs-install](./doc/markdown-images/install.png)

And on my local machine using VS, markdown preview extension it can see them fine.

When uploaded to gitea, it is trying to render this:
http://localhost:3000/Me/MyProject/media/branch/master/doc/markdown-images/install.png

Which gives a 404.

As you can see, the problem is that it is ignoring subfolders doc/markdown-images/

@stale stale bot removed the issue/stale label Apr 25, 2019
@worthy7
Copy link

worthy7 commented Apr 25, 2019

Ok, the problem it is needed to be like this:

  1. remove the ./ from the beginning
  2. use CAPS file extensions

![vs-install](doc/markdown-images/install.PNG)

@eapetitfils
Copy link

@worthy7 Yes, that's what I thought. This bug is about images that are embedded in the HTML since images do not exist as a separate file. For markdown, this was an issue with path only.

For this particular bug, the solution is trivial but imply some security questions. I could not find any credible exploit possible, but I am no security expert, are we happy if I modify it and do a pull request so that this can be discussed there instead of pushing the milestone here?

@worthy7
Copy link

worthy7 commented Apr 25, 2019

@eapetitfils Ah sorry, didn't mean to issue hijack.
I'm not sure what bug you are referring to in your second paragraph there, mine, or this issue3025

@eapetitfils
Copy link

@worthy7 no problem, at least the next person wondering why the images are not shown will see your answer.

The bug (or undesired feature as a matter of fact) I am referring to is this issue3025, not the markdown one.

@techknowlogick techknowlogick modified the milestones: 1.9.0, 1.10.0 Jun 4, 2019
@limenleap
Copy link

limenleap commented Jun 10, 2019

I got kind of a workaround. Not a good solution, but a workaround:

It looks to me that the sanitizer does not disturb a div tag with an ID.

So in Windows I wrote a batch file which just echoed that div thus:

@echo ^<div id='splview-%1' ^>Click here to view this file^</div^>

In the above statement %1 is the name of the temporary file that Gitea creates just before executing this batch file. (In Linux bash script, I think the parameter is $1 )

Now, before echoing out that statement, I of course did all the work (shhh...dont tell Gitea) and saved the converted HTML file somewhere else

Then in the custom template at custom\templates\custom\footer.tmpl at the Gitea executable folder; I wrote this script block

$('div[id^="splview-"]').click(function () {
    alert($(this).attr('id'));  
  //Instead of alerting... you should parse the id and
 //do whatever else that is needed to display the freshly constructed html
});

In my case, I am over-writing just one HTML file so for each file that uses this route, the eventual batch file generated HTML would be the same file (i.e. it is overwritten) -- at least that is what I plan to do.

I have reached till here -- now I need to write the code for popping up a separate window to display that batch file generated HTML ....

Note:
I had ensured that the custom/conf/app.ini file was configured to execute that batch file, as the external renderer, for the given filetype

Hope this works out. Fingers crossed

@stale
Copy link

stale bot commented Aug 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale stale bot added the issue/stale label Aug 9, 2019
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Aug 10, 2019
@stale stale bot removed the issue/stale label Aug 10, 2019
@techknowlogick techknowlogick modified the milestones: 1.10.0, 1.11.0 Sep 3, 2019
@techknowlogick techknowlogick modified the milestones: 1.11.0, 1.x.x Dec 30, 2019
@entron
Copy link

entron commented Jul 28, 2020

Same problem here. Any updates on this issue?

@mrsdizzie
Copy link
Member

You can now exclude classes from the sanitizer for these cases, described with example here:

https://docs.gitea.io/en-us/external-renderers/#appini-file-configuration

Other issue of generated image paths have been fixed previously as well.

@lunny lunny removed this from the 1.x.x milestone Sep 8, 2020
@entron
Copy link

entron commented Sep 20, 2020

@mrsdizzie Thanks for the update! Could you give an example for showing embeded plots in Jupyter notebooks? I couldn't find it in the documentation.

@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/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
Development

No branches or pull requests