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

Externally rendered markdown broken by 867f46f #8299

Closed
2 of 7 tasks
HarvsG opened this issue Sep 27, 2019 · 9 comments · Fixed by #8357
Closed
2 of 7 tasks

Externally rendered markdown broken by 867f46f #8299

HarvsG opened this issue Sep 27, 2019 · 9 comments · Fixed by #8357
Labels

Comments

@HarvsG
Copy link
Contributor

HarvsG commented 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

ctx.Data["MarkupType"] = markupType
added 1 month ago in 867f46f. 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

@HarvsG
Copy link
Contributor Author

HarvsG commented Sep 27, 2019

The other possible solution would be to edit

<div class="file-view {{if .IsMarkup}}{{.MarkupType}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">
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
Copy link
Contributor Author

HarvsG commented Sep 27, 2019

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

@HarvsG HarvsG changed the title Externally rendered markdown broken Externally rendered markdown broken by #7869 Sep 27, 2019
@HarvsG HarvsG changed the title Externally rendered markdown broken by #7869 Externally rendered markdown broken by 867f46f Sep 27, 2019
@lunny
Copy link
Member

lunny commented Sep 27, 2019

@HarvsG Please send a PR.

@noerw
Copy link
Member

noerw commented 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).

@HarvsG
Copy link
Contributor Author

HarvsG commented 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

<div class="file-view {{if .IsMarkup}}{{.MarkupType}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">

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

[markup.asciidoc]
ENABLED = false
; List of file extensions that should be rendered by an external command
FILE_EXTENSIONS = .adoc,.asciidoc
; External command to render all matching extensions
RENDER_COMMAND = "asciidoc --out-file=- -"
; Don't pass the file on STDIN, pass the filename as argument instead.
IS_INPUT_FILE = false

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

@noerw
Copy link
Member

noerw commented 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.

@lunny
Copy link
Member

lunny commented Sep 30, 2019

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

noerw added a commit to noerw/gitea that referenced this issue Oct 2, 2019
fixes go-gitea#8299, a regression from 867f46f.
unlike it's name suggests, the .markdown class is needed for most markup types.
a future refactor should rename this class to something more generic
@sapk sapk closed this as completed in #8357 Oct 3, 2019
sapk pushed a commit that referenced this issue Oct 3, 2019
fixes #8299, a regression from 867f46f.
unlike it's name suggests, the .markdown class is needed for most markup types.
a future refactor should rename this class to something more generic
@HarvsG
Copy link
Contributor Author

HarvsG commented 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
Copy link
Contributor Author

HarvsG commented Jul 16, 2020

@noerw I have opened a PR to work on this: #12261

@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants