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

Use a generic markup class to display externally rendered files and diffs #15735

Merged
merged 26 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4919bf6
creates and implements generic markup less class
HarvsG Jul 18, 2020
b5d5537
How to give custom CSS to externally rendered html
HarvsG Jul 18, 2020
273f6b0
Clarifies sources of CSS styling of markup
HarvsG Jul 18, 2020
5794c70
further clarification of sources of markup styling
HarvsG Jul 18, 2020
67b494d
rename _markdown to _markup
HarvsG Nov 19, 2020
e6f256c
remove defunct import
HarvsG Nov 19, 2020
82936c5
fix orphaned reference
HarvsG Apr 17, 2021
66d6337
remove comments
HarvsG Apr 17, 2021
29a2f09
fix header navigation
HarvsG Apr 17, 2021
dabed52
Merge branch 'master' into markup
6543 Apr 18, 2021
2bef1fe
Merge branch 'master' into markup
techknowlogick Apr 19, 2021
4e26e5c
Merge branch 'master' into markup
6543 May 5, 2021
416b54d
patch by @silverwind
6543 May 5, 2021
ead5a0b
Update docs/content/doc/advanced/external-renderers.en-us.md
6543 May 5, 2021
a122a98
more renames markdown -> markup
silverwind May 5, 2021
551a47c
do not suggest less customization
silverwind May 5, 2021
306f936
add back tokens
silverwind May 5, 2021
ae0b526
fix class whitespace, remove useless if-clause
silverwind May 5, 2021
32da837
Merge branch 'main' into markup
6543 May 5, 2021
944eb6c
remove unused csv-data rules
silverwind May 5, 2021
6eaea23
Merge branch 'main' into markup
6543 May 5, 2021
17cb028
Merge branch 'main' into markup
6543 May 6, 2021
4a2eed4
Merge branch 'main' into markup
techknowlogick May 7, 2021
0d47208
Merge branch 'main' into markup
techknowlogick May 7, 2021
91d9894
use named exports and rename functions
silverwind May 7, 2021
5fb5599
sort imports
silverwind May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions docs/content/doc/advanced/external-renderers.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,71 @@ Once your configuration changes have been made, restart Gitea to have changes ta

**Note**: Prior to Gitea 1.12 there was a single `markup.sanitiser` section with keys that were redefined for multiple rules, however,
there were significant problems with this method of configuration necessitating configuration through multiple sections.

## Customising CSS
6543 marked this conversation as resolved.
Show resolved Hide resolved
The external renderer is specified in the .ini in the format `[markup.XXXXX]` and the HTML supplied by your external renderer will be wrapped in a `<div>` with classes `markup` and `XXXXX`. The `markup` class provides out of the box styling (as does `markdown` if `XXXXX` is `markdown`). Otherwise you can use these classes to specifically target the contents of your rendered HTML.

And so you could write some Less:
```less
.markup.XXXXX {

html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

body {
color: #444;
font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
font-size: 12px;
line-height: 1.7;
padding: 1em;
margin: auto;
max-width: 42em;
background: #fefefe;
}

p {
color: orangered;
}
}
```
which is equivalent to:
```css
.markup.XXXXX html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

.markup.XXXXX body {
color: #444;
font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
font-size: 12px;
line-height: 1.7;
padding: 1em;
margin: auto;
max-width: 42em;
background: #fefefe;
}

.markup.XXXXX p {
color: orangered;
}
```
Add your stylesheet to your custom directory e.g `custom/public/css/my-style-XXXXX.less` or `custom/public/css/my-style-XXXXX.css`

Then to import it, add it to the custom header or footer. `custom/templates/custom/header.tmpl`
```html
<link rel="stylesheet/less" type="text/css" href="{{AppSubUrl}}/css/my-style-XXXXX.less" />
<script src="//cdn.jsdelivr.net/npm/less" ></script>
```

or if using pure CSS

```html
<link rel="stylesheet/less" type="text/css" href="{{AppSubUrl}}/css/my-style-XXXXX.css" />
```
2 changes: 1 addition & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<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">
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/diff/comment_form.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>
</div>
<div class="ui attached segment comment-body">
<div class="render-content markdown">
<div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/editor/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{{.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">
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/empty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<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}}
Expand All @@ -41,7 +41,7 @@ git push -u origin {{.Repository.DefaultBranch}}</code></pre>

<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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/comment_tab.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{- 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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/milestone_issues.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/milestones.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</div>
{{end}}
{{if .Content}}
<div class="markdown content">
<div class="markup content">
{{.RenderedContent|Str2html}}
</div>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</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}}
Expand Down Expand Up @@ -191,7 +191,7 @@
<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>
Expand Down
8 changes: 4 additions & 4 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
</div>
<div class="ui attached segment comment-body">
<div class="render-content markdown">
<div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
Expand Down Expand Up @@ -442,7 +442,7 @@
</span>
</div>
<div class="ui attached segment comment-body">
<div class="render-content markdown">
<div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
Expand Down Expand Up @@ -552,7 +552,7 @@
</div>
</div>
<div class="text comment-content">
<div class="render-content markdown">
<div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
Expand Down Expand Up @@ -739,7 +739,7 @@
</span>
</div>
<div class="ui attached segment">
<div class="render-content markdown">
<div class="render-content markup">
{{if .RenderedContent}}
{{.RenderedContent|Str2html}}
{{else}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/release/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
{{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">
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/release/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/settings/lfs_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
</h4>
<div class="ui attached table unstackable segment">
<div class="file-view {{if .IsMarkup}}markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}}">
<div class="file-view {{if .IsMarkup}}markup {{.MarkupType}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}}">
{{if .IsMarkup}}
{{if .FileContent}}{{.FileContent | Safe}}{{end}}
{{else if .IsRenderedHTML}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{{end}}
</h4>
<div class="ui attached table unstackable segment">
<div class="file-view {{if .IsMarkup}}{{.MarkupType}} {{if ne "csv" .MarkupType}}markdown{{end}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextSource}}code-view{{end}}">
<div class="file-view {{if .IsMarkup}}markup {{.MarkupType}} {{if ne "csv" .MarkupType}}{{end}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextSource}}code-view{{end}}">
{{if .IsMarkup}}
{{if .FileContent}}{{.FileContent | Safe}}{{end}}
{{else if .IsRenderedHTML}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/wiki/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{end}}
{{if $.RenderedDescription}}
<li>
<div class="render-content markdown">{{$.RenderedDescription|Str2html}}</div>
<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>
</li>
{{end}}
{{range .OpenIDs}}
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ function initWikiForm() {
text: plainText,
wiki: true
}, (data) => {
preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
preview.innerHTML = `<div class="markup ui segment">${data}</div>`;
renderMarkdownContent();
});
};
Expand Down Expand Up @@ -1555,7 +1555,7 @@ function initWikiForm() {
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',
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/markdown/anchors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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;
Expand All @@ -16,7 +16,7 @@ function scrollToAnchor() {
}

export default function initMarkdownAnchors() {
if (!document.querySelector('.markdown')) return;
if (!document.querySelector('.markup')) return;

for (const heading of document.querySelectorAll(headingSelector)) {
const originalId = heading.id.replace(/^user-content-/, '');
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/markdown/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const MAX_SOURCE_CHARACTERS = 5000;
function displayError(el, err) {
el.closest('pre').classList.remove('is-loading');
const errorNode = document.createElement('div');
errorNode.setAttribute('class', 'ui message error markdown-block-error mono');
errorNode.setAttribute('class', 'ui message error markup-block-error mono');
errorNode.textContent = err.str || err.message || String(err);
el.closest('pre').before(errorNode);
}
Expand Down
31 changes: 28 additions & 3 deletions web_src/less/_markdown.less → web_src/less/_markup.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.markdown:not(code) {
.markup:not(code) {
6543 marked this conversation as resolved.
Show resolved Hide resolved
overflow: hidden;
font-size: 16px;
line-height: 1.5 !important;
Expand Down Expand Up @@ -483,6 +483,31 @@
box-shadow: inset 0 -1px 0 var(--color-secondary);
}

.csv-data td,
.csv-data th {
padding: 5px;
overflow: hidden;
font-size: 12px;
line-height: 1;
text-align: left;
white-space: nowrap;
}

.csv-data .blob-num {
padding: 10px 8px 9px;
text-align: right;
border: 0;
}

.csv-data tr {
border-top: 0;
}

.csv-data th {
font-weight: 600;
border-top: 0;
}

.ui.list .list,
ol.ui.list ol,
ul.ui.list ul {
Expand Down Expand Up @@ -523,7 +548,7 @@
}
}

.markdown-block-error {
.markup-block-error {
margin-bottom: 0 !important;
border-bottom-left-radius: 0 !important;
border-bottom-right-radius: 0 !important;
Expand All @@ -534,7 +559,7 @@
text-align: left !important;
}

.markdown-block-error + pre {
.markup-block-error + pre {
border-top: none !important;
margin-top: 0 !important;
border-top-left-radius: 0 !important;
Expand Down
2 changes: 1 addition & 1 deletion web_src/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@import "_tribute";
@import "_font_i18n";
@import "_base";
@import "_markdown";
@import "_markup";
@import "_home";
@import "_install";
@import "_form";
Expand Down