-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use a generic markup class to display externally rendered files and diffs #12261
Conversation
The below shows how a markup renderer gets from the admin's The styling is then invoked by: gitea/templates/repo/view_file.tmpl Line 67 in 9542b73
Meaning that if it Where that dynamic class is obtained here Lines 466 to 468 in 9542b73
or Lines 512 to 516 in 9542b73
Using the gitea/modules/markup/markup.go Line 109 in 9542b73
which uses the gitea/modules/markup/markup.go Lines 53 to 56 in 9542b73
Which finds the file extension in a list of valid parsers: gitea/modules/markup/markup.go Lines 24 to 27 in 9542b73
Which are each registered by the RegisterParser function gitea/modules/markup/markup.go Line 45 in 9542b73
Which is called here: gitea/modules/markup/external/external.go Lines 21 to 25 in 704da08
Which is parsed from the app.ini file: gitea/modules/setting/markup.go Lines 126 to 132 in 1bf9e44
|
So the todo for the PR looks something like:
|
Codecov Report
|
Hmm the command |
Restarted. |
Typical use with screenshotsNative appearance of Install our converter software of choice on the gitea machine
If we open the resulting This looks promising..... add this it [markup.jupyter]
ENABLED = true
FILE_EXTENSIONS = .ipynb
RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template full "
IS_INPUT_FILE = true
[markup.sanitizer.jupyter0]
; jupyter chiefly uses divs
ELEMENT = div
ALLOW_ATTR = class
REGEXP = Appearance with styling inherited from the Since the CSS is stripped from the nbconvert output I removed and combined all the inline css, put it in a less file, wrapped the whole thing in I then added to <link rel="stylesheet/less" type="text/css" href="{{AppSubUrl}}/css/jupyter.less" />
<script src="//cdn.jsdelivr.net/npm/less" ></script> Final appearance with the |
I would imagine that many external renderers produce inline styling. It would be cool if the santizer could automatically extract, combine and scope the styles. Something to try another day. |
@HarvsG Great example for juypter render. Could you add an example on docs or could you save the comment as an article to our blog https://gitea.com/gitea/blog as a PR after merged? |
You can customerize allowed class and attributes via |
Hi @lunny, the PR contains a new how-to in the Docs here. I will create a PR request for the blog once we have merged. |
I'm not comfortable with removing the |
@@ -0,0 +1,496 @@ | |||
.markup:not(code) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need a:not()
? I'd prefer not to have that here. It adds CSS specificity (which makes styles harder to override) not to mention probably a few hundret bytes of CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to agree with @silverwind here. Why is there a :not(code)
here? There must be some way to prevent this from being needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think this is existing baggage with the .markdown:not(code)
selector. Not ideal that it's there, but no dealbreaker I guess and we can clean that up separately.
Oh and I don't get why this has to duplicate _markdown.css. Duplication should be avoided at all costs. I'd rather just use https://github.com/sindresorhus/github-markdown-css for the markdown styling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Duplication should be eliminated.
- Compatibilty with
.markdown
class should not be broken.
@silverwind Since markdown will not be the only supported file format to render. We should have |
Need to resolve #12261 (comment) before landing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per comment
@6543 @silverwind Should now be fixed in 29a2f09 |
@lafriks @silverwind this pull is ready to review ;) |
@@ -16,7 +16,7 @@ function scrollToAnchor() { | |||
} | |||
|
|||
export default function initMarkdownAnchors() { | |||
if (!document.querySelector('.markdown')) return; | |||
if (!document.querySelector('.markup')) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also need to update headingSelector
a few lines above. The fact that this change was necessary makes me suspicious thought, because I thought we'd have both classes present, e.g. markup markdown
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping both classes was my original proposition, but it was decided against because of duplication. #12261 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we swap markdown
class to markup
, we need to do replace all these matches:
$ egrep -ir class.+markdown templates | wc -l
32
$ egrep -ir class.+markdown web_src/js | wc -l
3
hmm I think this can be a next pull? @silverwind am I allowed to merge? |
I would not. It breaks markdown rendering in a lot of places in the UI with this halfway class rename (issue and pr comments, milestones, releases). |
Here is a patch of the cases I found in diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl
index 9b77ae6b3..5e0a53aa5 100644
--- a/templates/org/home.tmpl
+++ b/templates/org/home.tmpl
@@ -10,9 +10,9 @@
{{if .Org.Visibility.IsPrivate}}<div class="ui large basic horizontal label">{{.i18n.Tr "org.settings.visibility.private_shortname"}}</div>{{end}}
</span>
{{if .IsOrganizationOwner}}<a class="middle text grey" href="{{.OrgLink}}/settings">{{svg "octicon-gear" 16 "mb-3"}}</a>{{end}}
</div>
- {{if $.RenderedDescription}}<p class="render-content markdown">{{$.RenderedDescription|Str2html}}</p>{{end}}
+ {{if $.RenderedDescription}}<p class="render-content markup">{{$.RenderedDescription|Str2html}}</p>{{end}}
<div class="text grey meta">
{{if .Org.Location}}<div class="item">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
{{if .Org.Website}}<div class="item">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
</div>
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 4408d5257..187531f12 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -157,9 +157,9 @@
</div>
<div class="ui bottom attached active write tab segment">
<textarea class="review-textarea" tabindex="1" name="content"></textarea>
</div>
- <div class="ui bottom attached tab preview segment markdown">
+ <div class="ui bottom attached tab preview segment markup">
{{$.i18n.Tr "loading"}}
</div>
<div class="text right edit buttons">
<div class="ui basic blue cancel button" tabindex="3">{{.i18n.Tr "repo.issues.cancel"}}</div>
diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl
index c82d32c21..43e902bc8 100644
--- a/templates/repo/diff/comment_form.tmpl
+++ b/templates/repo/diff/comment_form.tmpl
@@ -21,14 +21,14 @@
<div class="field">
<div class="ui active tab" data-tab="write">
<textarea name="content" placeholder="{{$.root.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
</div>
- <div class="ui tab markdown" data-tab="preview">
+ <div class="ui tab markup" data-tab="preview">
{{.i18n.Tr "loading"}}
</div>
</div>
<div class="field footer">
- <span class="markdown-info">{{svg "octicon-markdown"}} {{$.root.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
+ <span class="markdown-info">{{svg "octicon-markup"}} {{$.root.i18n.Tr "repo.diff.comment.markup_info"}}</span>
<div class="ui right">
{{if $.reply}}
<button class="ui submit green tiny button btn-reply" type="submit">{{$.root.i18n.Tr "repo.diff.comment.reply"}}</button>
<input type="hidden" name="reply" value="{{$.reply}}">
diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl
index b566ffce9..6e39fbe85 100644
--- a/templates/repo/diff/comments.tmpl
+++ b/templates/repo/diff/comments.tmpl
@@ -50,9 +50,9 @@
{{template "repo/issue/view_content/context_menu" Dict "ctx" $.root "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
</div>
</div>
<div class="ui attached segment comment-body">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{$.root.i18n.Tr "repo.issues.no_content"}}</span>
diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl
index 3efde70f5..b7e1589aa 100644
--- a/templates/repo/editor/edit.tmpl
+++ b/templates/repo/editor/edit.tmpl
@@ -43,9 +43,9 @@
data-line-wrap-extensions="{{.LineWrapExtensions}}">
{{.FileContent}}</textarea>
<div class="editor-loading is-loading"></div>
</div>
- <div class="ui bottom attached tab segment markdown" data-tab="preview">
+ <div class="ui bottom attached tab segment markup" data-tab="preview">
{{.i18n.Tr "loading"}}
</div>
<div class="ui bottom attached tab segment diff edit-diff" data-tab="diff">
{{.i18n.Tr "loading"}}
diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl
index 7dae7c012..21c600545 100644
--- a/templates/repo/empty.tmpl
+++ b/templates/repo/empty.tmpl
@@ -26,9 +26,9 @@
<div class="ui divider"></div>
<div class="item">
<h3>{{.i18n.Tr "repo.create_new_repo_command"}}</h3>
- <div class="markdown">
+ <div class="markup">
<pre><code>touch README.md
git init
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
git add README.md
@@ -40,9 +40,9 @@ git push -u origin {{.Repository.DefaultBranch}}</code></pre>
<div class="ui divider"></div>
<div class="item">
<h3>{{.i18n.Tr "repo.push_exist_repo"}}</h3>
- <div class="markdown">
+ <div class="markup">
<pre><code>git remote add origin <span class="clone-url">{{if $.DisableSSH}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}</span>
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl
index ab874bdd1..77e82930d 100644
--- a/templates/repo/issue/comment_tab.tmpl
+++ b/templates/repo/issue/comment_tab.tmpl
@@ -7,9 +7,9 @@
<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.APIURL}}/markdown" data-context="{{.Repo.RepoLink}}">
{{- if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end -}}
</textarea>
</div>
- <div class="ui bottom tab markdown" data-tab="preview">
+ <div class="ui bottom tab markup" data-tab="preview">
{{.i18n.Tr "loading"}}
</div>
</div>
{{if .IsAttachmentEnabled}}
diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl
index 8c2f36f04..897d297d3 100644
--- a/templates/repo/issue/milestone_issues.tmpl
+++ b/templates/repo/issue/milestone_issues.tmpl
@@ -4,9 +4,9 @@
<div class="ui container">
<div class="ui three column stackable grid">
<div class="column">
<h1>{{.Milestone.Name}}</h1>
- <div class="markdown content">
+ <div class="markup content">
{{.Milestone.RenderedContent|Str2html}}
</div>
</div>
<div class="column center aligned">
diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl
index c7d3522ab..448d758e3 100644
--- a/templates/repo/issue/milestones.tmpl
+++ b/templates/repo/issue/milestones.tmpl
@@ -97,9 +97,9 @@
<a class="delete-button" href="#" data-url="{{$.RepoLink}}/milestones/delete" data-id="{{.ID}}">{{svg "octicon-trash"}} {{$.i18n.Tr "repo.issues.label_delete"}}</a>
</div>
{{end}}
{{if .Content}}
- <div class="markdown content">
+ <div class="markup content">
{{.RenderedContent|Str2html}}
</div>
{{end}}
</li>
diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl
index 0482604b7..e353d71ee 100644
--- a/templates/repo/issue/view_content.tmpl
+++ b/templates/repo/issue/view_content.tmpl
@@ -56,9 +56,9 @@
{{end}}
</div>
</div>
<div class="ui attached segment comment-body">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .Issue.RenderedContent}}
{{.Issue.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{.i18n.Tr "repo.issues.no_content"}}</span>
@@ -190,9 +190,9 @@
<div class="field">
<div class="ui bottom active tab write">
<textarea tabindex="1" name="content"></textarea>
</div>
- <div class="ui bottom tab preview markdown">
+ <div class="ui bottom tab preview markup">
{{$.i18n.Tr "loading"}}
</div>
</div>
{{if .IsAttachmentEnabled}}
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index 81f0d0434..4863f7f2f 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -63,9 +63,9 @@
{{end}}
</div>
</div>
<div class="ui attached segment comment-body">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
@@ -441,9 +441,9 @@
{{$.i18n.Tr "repo.issues.review.left_comment" | Safe}}
</span>
</div>
<div class="ui attached segment comment-body">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
@@ -551,9 +551,9 @@
{{end}}
</div>
</div>
<div class="text comment-content">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
@@ -738,9 +738,9 @@
{{$.i18n.Tr "action.review_dismissed_reason"}}
</span>
</div>
<div class="ui attached segment">
- <div class="render-content markdown">
+ <div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl
index ce4de3ddf..8f5a3c832 100644
--- a/templates/repo/release/list.tmpl
+++ b/templates/repo/release/list.tmpl
@@ -130,9 +130,9 @@
<span class="time">{{TimeSinceUnix .CreatedUnix $.Lang}}</span> |
{{end}}
<span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | EscapePound}}...{{.Target}}">{{$.i18n.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.i18n.Tr "repo.release.ahead.target" .Target}}</span>
</p>
- <div class="markdown desc">
+ <div class="markup desc">
{{Str2html .Note}}
</div>
<div class="ui accordion download">
<h2 class="title {{if eq $idx 0}}active{{end}} df ac mb-0">
diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl
index 8489d8959..c4b36597c 100644
--- a/templates/repo/release/new.tmpl
+++ b/templates/repo/release/new.tmpl
@@ -52,9 +52,9 @@
</div>
<div class="ui bottom active tab" data-tab="write">
<textarea name="content">{{.content}}</textarea>
</div>
- <div class="ui bottom tab markdown" data-tab="preview">
+ <div class="ui bottom tab markup" data-tab="preview">
{{$.i18n.Tr "loading"}}
</div>
</div>
{{range .attachments}}
diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl
index 0bc585886..fbb97db4a 100644
--- a/templates/repo/wiki/view.tmpl
+++ b/templates/repo/wiki/view.tmpl
@@ -60,9 +60,9 @@
<p>{{.FormatWarning}}</p>
</div>
{{end}}
<div class="ui {{if .sidebarPresent}}grid equal width{{end}}" style="margin-top: 1rem;">
- <div class="ui {{if .sidebarPresent}}eleven wide column{{end}} segment markdown">
+ <div class="ui {{if .sidebarPresent}}eleven wide column{{end}} segment markup">
{{.content | Str2html}}
</div>
{{if .sidebarPresent}}
<div class="column" style="padding-top: 0;">
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl
index 18f3c9f6d..29da93349 100644
--- a/templates/user/profile.tmpl
+++ b/templates/user/profile.tmpl
@@ -35,9 +35,9 @@
</li>
{{end}}
{{if $.RenderedDescription}}
<li>
- <div class="render-content markdown">{{$.RenderedDescription|Str2html}}</div>
+ <div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>
</li>
{{end}}
{{range .OpenIDs}}
{{if .Show}}
diff --git a/web_src/js/index.js b/web_src/js/index.js
index 1716df9e7..9992020e8 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -1473,9 +1473,9 @@ function initWikiForm() {
context: $editArea.data('context'),
text: plainText,
wiki: true
}, (data) => {
- preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
+ preview.innerHTML = `<div class="markup ui segment">${data}</div>`;
renderMarkdownContent();
});
};
@@ -1553,9 +1553,9 @@ function initWikiForm() {
hasSimpleMDE = false;
const $form = $('.repository.wiki.new .ui.form');
const $root = $form.find('.field.content');
const loading = $root.data('loading');
- $root.append(`<div class="ui bottom tab markdown" data-tab="preview">${loading}</div>`);
+ $root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
initCommentPreviewTab($form);
},
className: 'fa fa-file',
title: 'Revert to simple textarea',
diff --git a/web_src/js/markdown/anchors.js b/web_src/js/markdown/anchors.js
index 62561fe25..b25fddc59 100644
--- a/web_src/js/markdown/anchors.js
+++ b/web_src/js/markdown/anchors.js
@@ -1,7 +1,7 @@
import {svg} from '../svg.js';
-const headingSelector = '.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6';
+const headingSelector = '.markup h1, .markup h2, .markup h3, .markup h4, .markup h5, .markup h6';
function scrollToAnchor() {
if (document.querySelector(':target')) return;
if (!window.location.hash || window.location.hash.length <= 1) return; |
Should we still keep |
Generally I think it's unnecessary to have both classes but if we want to do something in JS/CSS specific to markdown, it would be good to have dual classes, so I'm not opposed to doing it now. GitHub is a btw a rather bad example on this, they have Also, it's possible that there are third-party integrations that work based of the |
can you sorry again resolve conflicts :/ |
Above patch also needs to be merged to fix markdown rendering all over the place. Maybe someone should raise another PR with the patch merged. |
Please resolve the conflicts. |
-> #15735 |
This PR will be a follow-on from #8299 and #7614.
It builds on the work done in #8300 and the patch #8357
The idea is to have a generic class
.markup
that has some default rendering, that is near identical to the current.markdown
The current
.markdown
is defined athttps://github.com/go-gitea/gitea/blob/master/web_src/less/_markdown.less
and overwritten at:
gitea/web_src/less/themes/theme-arc-green.less
Lines 851 to 885 in 84a419d
and
gitea/web_src/less/themes/theme-arc-green.less
Lines 1856 to 1867 in 84a419d