Externally rendered markdown broken by 867f46f #4023

Closed
opened 2025-11-02 05:34:36 -06:00 by GiteaMirror · 9 comments
Owner

Originally created by @HarvsG on GitHub (Sep 27, 2019).

  • Gitea version (or commit ref):
  • Git version:
  • Operating system:
  • 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

Somewhere between gitea version 1.8.2 and master the display of rendered html has changed in the repo view.

both using the same render command: RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template full "
In both cases nbconvert==5.6.0
In the latest version it passes the HTML as below with class=jupyter, this results in unstyled HTML

<div class="file-view jupyter has-emoji">
  <div id="notebook">
    <div id="notebook-container">

However, previously it would pass class=markdown which would maintain styling:

<div class="file-view markdown has-emoji">
  <div id="notebook">
    <div id="notebook-container">

Using the chrome inspector to edit the class from jupyter to markdown fixes this and returns styling.

The culprit line appears to be line c6fb7fe27c/routers/repo/view.go (L288) added 1 month ago in 867f46f78e. This was a fix for #7868 (pull request #7869).

A quick fix would be to change the above line to:
ctx.Data["MarkupType"] = markupType + " markdown".

...

Screenshots

Current appearance in master.
Screenshot 2019-09-27 at 09 57 36
Old appearance in v1.82 or after adding class=markdown in master
Screenshot 2019-09-27 at 09 56 37

Originally created by @HarvsG on GitHub (Sep 27, 2019). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): - Git version: - Operating system: - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [x] No - [ ] Not relevant - Log gist: ## Description Somewhere between gitea version 1.8.2 and `master` the display of rendered html has changed in the repo view. both using the same render command: RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template full " In both cases `nbconvert==5.6.0` In the latest version it passes the HTML as below with `class=jupyter`, this results in unstyled HTML ``` HTML <div class="file-view jupyter has-emoji"> <div id="notebook"> <div id="notebook-container"> ``` However, previously it would pass `class=markdown` which would maintain styling: ``` HTML <div class="file-view markdown has-emoji"> <div id="notebook"> <div id="notebook-container"> ``` Using the chrome inspector to edit the class from `jupyter` to `markdown` fixes this and returns styling. The culprit line appears to be line https://github.com/go-gitea/gitea/blob/c6fb7fe27c16c4e43d4d8dbe4d2ff4b3c4c52a29/routers/repo/view.go#L288 added 1 month ago in https://github.com/go-gitea/gitea/commit/867f46f78e5777d7bafe83cda3244c1001ce3e60. This was a fix for #7868 (pull request #7869). A quick fix would be to change the above line to: `ctx.Data["MarkupType"] = markupType + " markdown"`. ... ## Screenshots Current appearance in `master`. ![Screenshot 2019-09-27 at 09 57 36](https://user-images.githubusercontent.com/11440490/65761819-826a1b00-e117-11e9-905f-faaad662bfe0.png) Old appearance in v1.82 or after adding `class=markdown` in `master` ![Screenshot 2019-09-27 at 09 56 37](https://user-images.githubusercontent.com/11440490/65761823-84cc7500-e117-11e9-80b3-93875d9e01fe.png) <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/bug label 2025-11-02 05:34:36 -06:00
Author
Owner

@HarvsG commented on GitHub (Sep 27, 2019):

The other possible solution would be to edit 867f46f78e/templates/repo/view_file.tmpl (L48) to:
<div class="file-view {{if .IsMarkup}}{{.MarkupType}} markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">

However both of these solutions run the risk of creating class=markdown markdown which is not very elegant.

@HarvsG commented on GitHub (Sep 27, 2019): The other possible solution would be to edit https://github.com/go-gitea/gitea/blob/867f46f78e5777d7bafe83cda3244c1001ce3e60/templates/repo/view_file.tmpl#L48 to: `<div class="file-view {{if .IsMarkup}}{{.MarkupType}} markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">` However both of these solutions run the risk of creating `class=markdown markdown` which is not very elegant.
Author
Owner

@HarvsG commented on GitHub (Sep 27, 2019):

Paging @noerw, would either of these mess with what you achieved in #7869 and #7868?

@HarvsG commented on GitHub (Sep 27, 2019): Paging @noerw, would either of these mess with what you achieved in #7869 and #7868?
Author
Owner

@lunny commented on GitHub (Sep 27, 2019):

@HarvsG Please send a PR.

@lunny commented on GitHub (Sep 27, 2019): @HarvsG Please send a PR.
Author
Owner

@noerw commented on GitHub (Sep 28, 2019):

@HarvsG Hej, I was not aware that the markdown CSS class would be needed for other types than .md files. If thats the case, reusing this class for multiple formats seems kinda hacky and is hard to follow while reading the code. I changed the behaviour, so that custom styling for CSV files would be possible while making the gitea template more structured.

If the old behaviour should be restored, I'd propose to introduce a new styling class for each markupType eg html, and rename the markdown class to something more generic (external-render?).
While more hacky, your quick fix would mostly preserve the current behaviour for CSV files (just larger margins around the table afaik).

@noerw commented on GitHub (Sep 28, 2019): @HarvsG Hej, I was not aware that the `markdown` CSS class would be needed for other types than `.md` files. If thats the case, reusing this class for multiple formats seems kinda hacky and is hard to follow while reading the code. I changed the behaviour, so that custom styling for CSV files would be possible while making the gitea template more structured. If the old behaviour should be restored, I'd propose to introduce a new styling class for each markupType eg `html`, and rename the `markdown` class to something more generic (`external-render`?). While more hacky, your quick fix would mostly preserve the current behaviour for CSV files (just larger margins around the table afaik).
Author
Owner

@HarvsG commented on GitHub (Sep 28, 2019):

@noerw, Agreed. However the current markdown class does quite a good job of turning the plain HTML put out by by renderers such as pandoc and nbconvert into attractive formatting.

Perhaps we could create a copy of the current markdown class called something like html, external-render or markup and instead pass that as the default in 867f46f78e/templates/repo/view_file.tmpl (L48)
E.g
<div class="file-view {{if .IsMarkup}}markup {{.MarkupType}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">

markup would have the elegant result of allowing users to write their own custom CSS in the format of .markup.asciidoc or .markup.csv which is exactly the same format that the custom renderers are specified in app.ini c6fb7fe27c/custom/conf/app.ini.sample (L797-L804)

@noerw If you think this is a good idea, would you would be able to help me with the CSS changes as my CSS is weak, much less my 'less' skills.

@HarvsG commented on GitHub (Sep 28, 2019): @noerw, Agreed. However the current `markdown` class does quite a good job of turning the plain HTML put out by by renderers such as pandoc and nbconvert into attractive formatting. Perhaps we could create a copy of the current `markdown` class called something like `html`, `external-render` or `markup` and instead pass that as the default in https://github.com/go-gitea/gitea/blob/867f46f78e5777d7bafe83cda3244c1001ce3e60/templates/repo/view_file.tmpl#L48 E.g `<div class="file-view {{if .IsMarkup}}markup {{.MarkupType}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">` `markup` would have the elegant result of allowing users to write their own custom CSS in the format of `.markup.asciidoc` or `.markup.csv` which is exactly the same format that the custom renderers are specified in app.ini https://github.com/go-gitea/gitea/blob/c6fb7fe27c16c4e43d4d8dbe4d2ff4b3c4c52a29/custom/conf/app.ini.sample#L797-L804 @noerw If you think this is a good idea, would you would be able to help me with the CSS changes as my CSS is weak, much less my 'less' skills.
Author
Owner

@noerw commented on GitHub (Sep 30, 2019):

Your proposal sounds good, but refactoring this will need some elaborate manual testing (or is there a frontend test suite?).
So I'd revert the problematic change for now (so this affects only csv rendering in a minor way, I can send a PR this week), and do a proper refactor of the CSS classes as a second step.

@noerw commented on GitHub (Sep 30, 2019): Your proposal sounds good, but refactoring this will need some elaborate manual testing (or is there a frontend test suite?). So I'd revert the problematic change for now (so this affects only csv rendering in a minor way, I can send a PR this week), and do a proper refactor of the CSS classes as a second step.
Author
Owner

@lunny commented on GitHub (Sep 30, 2019):

So let's sent two PRs. One for bug fix and another for a refactoring. :)

@lunny commented on GitHub (Sep 30, 2019): So let's sent two PRs. One for bug fix and another for a refactoring. :)
Author
Owner

@HarvsG commented on GitHub (Oct 6, 2019):

@noerw, thank you for doing this in #8357, should we now explore the idea of the more general markup class and switching to this?

@HarvsG commented on GitHub (Oct 6, 2019): @noerw, thank you for doing this in #8357, should we now explore the idea of the more general `markup` class and switching to this?
Author
Owner

@HarvsG commented on GitHub (Jul 16, 2020):

@noerw I have opened a PR to work on this: https://github.com/go-gitea/gitea/pull/12261

@HarvsG commented on GitHub (Jul 16, 2020): @noerw I have opened a PR to work on this: https://github.com/go-gitea/gitea/pull/12261
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4023