#249 Render HTML files

Open
opened 3 weeks ago by ivan-paleo · 31 comments

Apparently, just like GitHub, HTML files are not rendered on Codeberg.
For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn’t work with Codeberg repos.

It is not an issue per se, maybe more like a feature request. Or maybe there is already a way to deal with this.

Thanks!

Apparently, just like GitHub, HTML files are not rendered on Codeberg. For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn't work with Codeberg repos. It is not an issue per se, maybe more like a feature request. Or maybe there is already a way to deal with this. Thanks!
lhinderberger commented 3 weeks ago
Collaborator

A similar solution could be implemented using Codeberg Pages.

Maybe we can ask the authors of htmlpreview to put their site under a free software license. That way we could simply re-use it here. See next comment below :)

A similar solution could be implemented using [Codeberg Pages](https://pages.codeberg.org/). ~~Maybe we can ask the authors of htmlpreview to put their site under a free software license. That way we could simply re-use it here.~~ See next comment below :)
lhinderberger added the
enhancement
label 3 weeks ago
lhinderberger added the
help wanted
label 3 weeks ago
lhinderberger commented 3 weeks ago
Collaborator

Oh, I just saw in the README of https://github.com/htmlpreview/htmlpreview.github.com that they have put it under the Apache License 2.0 :)

Oh, I just saw in the README of https://github.com/htmlpreview/htmlpreview.github.com that they have put it under the Apache License 2.0 :)
lhinderberger commented 3 weeks ago
Collaborator

Looking at the code, it seems to be quite closely tied to Github / Bitbucket and it seems to use an external proxy. So 1-to-1 adaption won’t work. But it might be a good base to develop a variant that works for Codeberg.

Would you be interested in developing such an adaption? :)

For Media proxy, there’s already an issue open: #196

Looking at the code, it seems to be quite closely tied to Github / Bitbucket and it seems to use an external proxy. So 1-to-1 adaption won't work. But it might be a good base to develop a variant that works for Codeberg. Would you be interested in developing such an adaption? :) For Media proxy, there's already an issue open: #196
ivan-paleo commented 3 weeks ago
Poster

Euu... I would be interested in testing it, but I definitely have no idea about this kind of software... I use GitHub/Codeberg for R projects only; that’s where my programming skills start and end!

Euu... I would be interested in testing it, but I definitely have no idea about this kind of software... I use GitHub/Codeberg for R projects only; that's where my programming skills start and end!
ivan-paleo commented 3 weeks ago
Poster

A similar solution could be implemented using Codeberg Pages.

As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis. That’s why I think that having an HTML viewer (either built-in, the best case, or external like for GitHub) is the only solution.

But that means there is already a built-in tool to render HTML files. Could it be extended to repos as well? Like having the option to either show rendered or raw?

> A similar solution could be implemented using [Codeberg Pages](https://pages.codeberg.org/). > As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis. That's why I think that having an HTML viewer (either built-in, the best case, or external like for GitHub) is the only solution. But that means there is already a built-in tool to render HTML files. Could it be extended to repos as well? Like having the option to either show rendered or raw?
ivan-paleo commented 3 weeks ago
Poster

And by the way, being able to render HTML files would be an advantage over GitHub. Judging by the number of threads to ask how to render HTML files on GitHub, it seems there is a need for such a feature. It would be a nice “unique selling point” for Codeberg.

And by the way, being able to render HTML files would be an advantage over GitHub. Judging by the number of threads to ask how to render HTML files on GitHub, it seems there is a need for such a feature. It would be a nice "unique selling point" for Codeberg.
lhinderberger commented 3 weeks ago
Collaborator

No problem :) Maybe someone else can have a look at the programming side of this.

It looks like htmlpreview works by fetching and rendering the HTML files with the help of JavaScript. That’s why it would be possible to deploy it to Pages, which would be a relatively quick and easy fix for the problem you have described regarding Rmd scripts.

But you’re right, there are other more integrated and user-friendly options like extending Gitea to display HTML previews, although there are considerations to be made, especially in regards of security.

Let’s wait for some more feedback of the other people on Codeberg (Codebergians? Codebergers? 😄).

No problem :) Maybe someone else can have a look at the programming side of this. It looks like htmlpreview works by fetching and rendering the HTML files with the help of JavaScript. That's why it would be possible to deploy it to Pages, which would be a relatively quick and easy fix for the problem you have described regarding Rmd scripts. But you're right, there are other more integrated and user-friendly options like extending Gitea to display HTML previews, although there are considerations to be made, especially in regards of security. Let's wait for some more feedback of the other people on Codeberg (Codebergians? Codebergers? :smile:).
n commented 3 weeks ago

For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn’t work with Codeberg repos.

I put together a quick fork for htmlpreview at htmlpreview.codeberg.eu for use with Codeberg repos. It’s only a short term solution, hopefully we can get a preview option on Gitea.

> For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn't work with Codeberg repos. I put together a quick fork for htmlpreview at [htmlpreview.codeberg.eu](https://htmlpreview.codeberg.eu/) for use with Codeberg repos. It's only a short term solution, hopefully we can get a preview option on Gitea.
ivan-paleo commented 3 weeks ago
Poster

For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn’t work with Codeberg repos.

I put together a quick fork for htmlpreview at htmlpreview.codeberg.eu for use with Codeberg repos. It’s only a short term solution, hopefully we can get a preview option on Gitea.

Of course, a preview option would be best, but your fork for htmlpreview is already wonderful, especially in such a short time!

> > For GitHub repos, it is possible to use https://htmlpreview.github.io/, but it doesn't work with Codeberg repos. > > I put together a quick fork for htmlpreview at [htmlpreview.codeberg.eu](https://htmlpreview.codeberg.eu/) for use with Codeberg repos. It's only a short term solution, hopefully we can get a preview option on Gitea. Of course, a preview option would be best, but your fork for htmlpreview is already wonderful, especially in such a short time!
hw commented 3 weeks ago
Owner

But that means there is already a built-in tool to render HTML files. Could it be extended to repos as well? Like having the option to either show rendered or raw?

This would be a nice contribution to gitea (toggle between source and preview for all preview-able file formats).

> But that means there is already a built-in tool to render HTML files. Could it be extended to repos as well? Like having the option to either show rendered or raw? This would be a nice contribution to gitea (toggle between source and preview for all preview-able file formats).
ivan-paleo commented 2 weeks ago
Poster

I put together a quick fork for htmlpreview at htmlpreview.codeberg.eu for use with Codeberg repos. It’s only a short term solution, hopefully we can get a preview option on Gitea.

For an unknown reason, when I add a link to the HTML file preview in a README.md (e.g. [file](https://htmlpreview.codeberg.eu/?https://codeberg.org/ivan-paleo/initiationR/src/branch/master/initiationR.html), I get this error when I click on the link:

Error: Cannot load https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html=: 404 Invalid host

But if I copy the URL into the browser, the HTML file is previewed nicely.

Any idea what’s wrong?

> I put together a quick fork for htmlpreview at [htmlpreview.codeberg.eu](https://htmlpreview.codeberg.eu/) for use with Codeberg repos. It's only a short term solution, hopefully we can get a preview option on Gitea. For an unknown reason, when I add a link to the HTML file preview in a README.md (e.g. `[file](https://htmlpreview.codeberg.eu/?https://codeberg.org/ivan-paleo/initiationR/src/branch/master/initiationR.html)`, I get this error when I click on the link: Error: Cannot load https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html=: 404 Invalid host But if I copy the URL into the browser, the HTML file is previewed nicely. Any idea what's wrong?
6543 commented 2 weeks ago
Collaborator

@hw @lhinderberger @ivan-paleo it is posible

just add this to app.ini:

[markup.html]
ENABLED = true
FILE_EXTENSIONS = .html
RENDER_COMMAND = "cat"
IS_INPUT_FILE = false
@hw @lhinderberger @ivan-paleo it is posible just add this to app.ini: ```ini [markup.html] ENABLED = true FILE_EXTENSIONS = .html RENDER_COMMAND = "cat" IS_INPUT_FILE = false ```
ivan-paleo commented 2 weeks ago
Poster

@6543 Sorry for being programmatically limited... But where should these commands be added? I guess I cannot/shouldn’t be the one doing it...

@6543 Sorry for being programmatically limited... But where should these commands be added? I guess I cannot/shouldn't be the one doing it...
6543 commented 2 weeks ago
Collaborator

@ivan-paleo for you it’s just an info - you don programm it, this are settigns

@ivan-paleo for you it's just an info - you don programm it, this are settigns
ivan-paleo commented 2 weeks ago
Poster

@ivan-paleo for you it’s just an info - you don programm it, this are settigns

Ah OK, thank you. Then, I’ll just wait until someone competent takes care of it :)

> @ivan-paleo for you it's just an info - you don programm it, this are settigns Ah OK, thank you. Then, I'll just wait until someone competent takes care of it :)
lhinderberger commented 2 weeks ago
Collaborator

just add this to app.ini

What are the privacy / security implications - wouldn’t it allow XSS attacks?

> just add this to app.ini What are the privacy / security implications - wouldn't it allow XSS attacks?
lhinderberger commented 2 weeks ago
Collaborator

Any idea what’s wrong?

That’s just a guess, but I could imagine two things that could have gone wrone:

  • Maybe you need to URL-encode your link, so the link address becomes https://htmlpreview.codeberg.eu/?https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html
  • Maybe htmlpreview needs to explicitly urldecode the link passed into it?
> Any idea what's wrong? That's just a guess, but I could imagine two things that could have gone wrone: - Maybe you need to URL-encode your link, so the link address becomes `https://htmlpreview.codeberg.eu/?https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html` - Maybe htmlpreview needs to explicitly urldecode the link passed into it?
hw commented 2 weeks ago
Owner

@hw @lhinderberger @ivan-paleo it is posible

just add this to app.ini:

[markup.html]
ENABLED = true
FILE_EXTENSIONS = .html
RENDER_COMMAND = "cat"
IS_INPUT_FILE = false

What about javascript/external security issues/source sanitization?

> @hw @lhinderberger @ivan-paleo it is posible > > just add this to app.ini: > > ```ini > [markup.html] > ENABLED = true > FILE_EXTENSIONS = .html > RENDER_COMMAND = "cat" > IS_INPUT_FILE = false > ``` What about javascript/external security issues/source sanitization?
hw commented 2 weeks ago
Owner

A similar solution could be implemented using Codeberg Pages.

As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis.

why shouldn’t this work with Codeberg pages? You can put both in the repo.

(this is not to say that HTML preview wouldn’t be cool. We just need to be careful to do it properly and not create security issues)

> > A similar solution could be implemented using [Codeberg Pages](https://pages.codeberg.org/). > > > > As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis. why shouldn't this work with Codeberg pages? You can put both in the repo. (this is not to say that HTML preview wouldn't be cool. We just need to be careful to do it properly and not create security issues)
ivan-paleo commented 2 weeks ago
Poster

A similar solution could be implemented using Codeberg Pages.

As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis.

why shouldn’t this work with Codeberg pages? You can put both in the repo.

(this is not to say that HTML preview wouldn’t be cool. We just need to be careful to do it properly and not create security issues)

I totally agree with you about doing things properly!

I still cannot imagine how pages would help me here... Do you mean that I should/could copy/move the HTML file(s) from my repo to my pages, and then link to the file(s) in my pages from the repo? The files are generating by rendering my R scripts, so I would need to additionally copy/move the files to my pages... Possible but not quite ideal. But maybe I just do not really understand how pages work.

Still, I am wondering why HTML files can be rendered/previewed in pages but not in repos. Doesn’t it mean that the functionality is there and that it could “just” be added to the repos?

> > > A similar solution could be implemented using [Codeberg Pages](https://pages.codeberg.org/). > > > > > > > As far as I understand it, Pages would not help me in that case because I render Rmd scripts to HTML. These HTML files have to be in the same repo as the rest of the analysis. > > why shouldn't this work with Codeberg pages? You can put both in the repo. > > (this is not to say that HTML preview wouldn't be cool. We just need to be careful to do it properly and not create security issues) > I totally agree with you about doing things properly! I still cannot imagine how pages would help me here... Do you mean that I should/could copy/move the HTML file(s) from my repo to my pages, and then link to the file(s) in my pages from the repo? The files are generating by rendering my R scripts, so I would need to additionally copy/move the files to my pages... Possible but not quite ideal. But maybe I just do not really understand how pages work. Still, I am wondering why HTML files can be rendered/previewed in pages but not in repos. Doesn't it mean that the functionality is there and that it could "just" be added to the repos?
ivan-paleo commented 2 weeks ago
Poster
  • Maybe you need to URL-encode your link, so the link address becomes https://htmlpreview.codeberg.eu/?https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html

That doesn’t help unfortunately, same error...

> - Maybe you need to URL-encode your link, so the link address becomes `https://htmlpreview.codeberg.eu/?https%3A%2F%2Fcodeberg.org%2Fivan-paleo%2FinitiationR%2Fsrc%2Fbranch%2Fmaster%2FinitiationR.html` That doesn't help unfortunately, same error...
hw commented 2 weeks ago
Owner

Do you mean that I should/could copy/move the HTML file(s) from my repo to my pages, and then link to the file(s) in my pages from the repo? The files are generating by rendering my R scripts, so I would need to additionally copy/move the files to my pages... Possible but not quite ideal. But maybe I just do not really understand how pages work.

You understand it correctly, that’s exactly how it works -- codeberg pages is merely a versioned deployment storage facility: ;)

  • author the content in your content repo,
  • compile it to generate deployment files (in your case run the R script[s]),
  • deploy the compiled files and all dependencies to the pages repo.

You might for example using a script like this: https://codeberg.org/Codeberg/Documentation/src/branch/master/deploy.sh

  • (instead of git@codeberg.org:docs/pages.git you specify your own pages repo URL),
  • (instead of npm build you call your R script),
  • (instead of _site/* you specify the list/wildcard of your generated files and dependencies).

Doesn’t it mean that the functionality is there and that it could “just” be added to the repos?

The pages functionality is currently not part of gitea core (yet?), but external.

> Do you mean that I should/could copy/move the HTML file(s) from my repo to my pages, and then link to the file(s) in my pages from the repo? The files are generating by rendering my R scripts, so I would need to additionally copy/move the files to my pages... Possible but not quite ideal. But maybe I just do not really understand how pages work. You understand it correctly, that's exactly how it works -- codeberg pages is merely a versioned deployment storage facility: ;) - author the content in your content repo, - compile it to generate deployment files (in your case run the R script[s]), - deploy the compiled files and all dependencies to the pages repo. You might for example using a script like this: https://codeberg.org/Codeberg/Documentation/src/branch/master/deploy.sh - (instead of `git@codeberg.org:docs/pages.git` you specify your own pages repo URL), - (instead of `npm build` you call your R script), - (instead of `_site/*` you specify the list/wildcard of your generated files and dependencies). > Doesn’t it mean that the functionality is there and that it could “just” be added to the repos? The pages functionality is currently not part of gitea core (yet?), but external.
6543 commented 2 weeks ago
Collaborator

@hw you will have the default sanitization for markdown

@hw you will have the default sanitization for markdown
hw commented 2 weeks ago
Owner

@hw you will have the default sanitization for markdown

we still need to wrap html into iframe, right?

> @hw you will have the default sanitization for markdown we still need to wrap html into iframe, right?
6543 commented 2 weeks ago
Collaborator

it depends how your html files look like

it depends how your html files look like
hw commented 2 weeks ago
Owner

would it be of general interest to wrap all user content into <iframe sandbox ...> within gitea? This would also resolve the long-standing SVG security concerns?

would it be of general interest to wrap all user content into `<iframe sandbox ...>` within gitea? This would also resolve the long-standing SVG security concerns?
lhinderberger commented 2 weeks ago
Collaborator

In combination with the media proxy from #196 to protect against unwanted tracking, that would be a good idea.

In combination with the media proxy from #196 to protect against unwanted tracking, that would be a good idea.
hw commented 2 weeks ago
Owner

What is the general feeling, should files like HTML get rendered as source code or preview (for the time being where we have no toggle button to switch between preview and source view?)

What is the general feeling, should files like HTML get rendered as source code or preview (for the time being where we have no toggle button to switch between preview and source view?)
lhinderberger commented 2 weeks ago
Collaborator

I’d vote for rendering them as source code and using n’s htmlpreview fork as an interim solution.

I'd vote for rendering them as source code and using n's htmlpreview fork as an interim solution.
ivan-paleo commented 2 weeks ago
Poster

I would of course prefer to preview them, but that’s due to my use of HTML files (as “reports” - the source code is irrelevant for me).

The HTML preview (given the links work correctly) is also a good interim solution.

I would of course prefer to preview them, but that's due to my use of HTML files (as "reports" - the source code is irrelevant for me). The HTML preview (given the links work correctly) is also a good interim solution.
hw commented 1 week ago
Owner

sounds like having a toggle switch is the way to go then? This would be a gitea feature?

sounds like having a toggle switch is the way to go then? This would be a gitea feature?
hw added the
gitea-related issue
label 1 week ago
Sign in to join this conversation.
No Milestone
No Assignees
5 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.