Skip to content

Commit 53571d6

Browse files
committed
fix
1 parent e3e3260 commit 53571d6

28 files changed

+132
-107
lines changed

modules/web/route.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"reflect"
1010
"strings"
1111

12+
"code.gitea.io/gitea/modules/htmlutil"
1213
"code.gitea.io/gitea/modules/setting"
1314
"code.gitea.io/gitea/modules/web/middleware"
1415

@@ -214,7 +215,9 @@ func (r *Router) normalizeRequestPath(resp http.ResponseWriter, req *http.Reques
214215
normalizedPath = "/"
215216
} else if !strings.HasPrefix(normalizedPath+"/", "/v2/") {
216217
// do not respond to other requests, to simulate a real sub-path environment
217-
http.Error(resp, "404 page not found, sub-path is: "+setting.AppSubURL, http.StatusNotFound)
218+
resp.Header().Add("Content-Type", "text/html; charset=utf-8")
219+
resp.WriteHeader(http.StatusNotFound)
220+
_, _ = resp.Write([]byte(htmlutil.HTMLFormat(`404 page not found, sub-path is: <a href="%s">%s</a>`, setting.AppSubURL, setting.AppSubURL)))
218221
return
219222
}
220223
normalized = true

options/locale/locale_en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,6 @@ diff.generated = generated
25882588
diff.vendored = vendored
25892589
diff.comment.add_line_comment = Add line comment
25902590
diff.comment.placeholder = Leave a comment
2591-
diff.comment.markdown_info = Styling with markdown is supported.
25922591
diff.comment.add_single_comment = Add single comment
25932592
diff.comment.add_review_comment = Add comment
25942593
diff.comment.start_review = Start review

routers/web/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ func registerRoutes(m *web.Router) {
485485
m.Methods("GET, HEAD", "/*", public.FileHandlerFunc())
486486
}, optionsCorsHandler())
487487

488+
m.Post("/-/markup", reqSignIn, web.Bind(structs.MarkupOption{}), misc.Markup)
489+
488490
m.Group("/explore", func() {
489491
m.Get("", func(ctx *context.Context) {
490492
ctx.Redirect(setting.AppSubURL + "/explore/repos")

templates/devtest/devtest-footer.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{/* TODO: the devtest.js is isolated from index.js, so no module is shared and many index.js functions do not work in devtest.ts */}}
22
<script src="{{AssetUrlPrefix}}/js/devtest.js?v={{AssetVersion}}"></script>
3-
{{template "base/footer" dict}}
3+
{{template "base/footer" ctx.RootData}}

templates/devtest/devtest-header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{{template "base/head" dict}}
1+
{{template "base/head" ctx.RootData}}
22
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/devtest.css?v={{AssetVersion}}">

templates/devtest/gitea-ui.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@
183183

184184
<div>
185185
<h1>ComboMarkdownEditor</h1>
186-
<div>ps: no JS code attached, so just a layout</div>
187-
{{template "shared/combomarkdowneditor" .}}
186+
{{template "shared/combomarkdowneditor" dict "MarkdownPreviewContext" "/owner/path"}}
188187
</div>
189188

190189
<h1>Tailwind CSS Demo</h1>

templates/org/settings/options.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<input id="email" name="email" type="email" value="{{.Org.Email}}" maxlength="255">
2424
</div>
2525
<div class="field {{if .Err_Description}}error{{end}}">
26+
{{/* it is rendered as markdown, but the length is limited, so at the moment we do not use the markdown editor here */}}
2627
<label for="description">{{ctx.Locale.Tr "org.org_desc"}}</label>
2728
<textarea id="description" name="description" rows="2" maxlength="255">{{.Org.Description}}</textarea>
2829
</div>

templates/projects/new.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
</div>
1919
<div class="field">
2020
<label>{{ctx.Locale.Tr "repo.projects.description"}}</label>
21-
<textarea name="content" placeholder="{{ctx.Locale.Tr "repo.projects.description_placeholder"}}">{{.content}}</textarea>
21+
{{/* TODO: repo-level project and org-level project have different behaviros to render */}}
22+
{{/* the "Repository" is nil when the project is org-level */}}
23+
{{template "shared/combomarkdowneditor" (dict
24+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewContext" (Iif $.Repository "" .HomeLink) "MarkdownPreviewMode" (Iif $.Repository "comment")
25+
"TextareaName" "content" "TextareaContent" .content "TextareaPlaceholder" (ctx.Locale.Tr "repo.projects.description_placeholder")
26+
)}}
2227
</div>
2328

2429
{{if not .PageIsEditProjects}}

templates/repo/diff/box.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@
240240
<template id="issue-comment-editor-template">
241241
<div class="ui form comment">
242242
{{template "shared/combomarkdowneditor" (dict
243-
"MarkdownPreviewUrl" (print $.Repository.Link "/markup")
244-
"MarkdownPreviewContext" $.RepoLink
243+
"CustomInit" true
244+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
245245
"TextareaName" "content"
246246
"DropzoneParentContainer" ".ui.form"
247247
)}}

templates/repo/diff/comment_form.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
<input type="hidden" name="diff_base_cid">
1212

1313
{{template "shared/combomarkdowneditor" (dict
14-
"MarkdownPreviewUrl" (print $.root.Repository.Link "/markup")
15-
"MarkdownPreviewContext" $.root.RepoLink
16-
"TextareaName" "content"
17-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder")
14+
"CustomInit" true
15+
"MarkdownPreviewInRepo" $.root.Repository "MarkdownPreviewMode" "comment"
16+
"TextareaName" "content" "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder")
1817
"DropzoneParentContainer" "form"
1918
"DisableAutosize" "true"
2019
)}}
@@ -26,7 +25,6 @@
2625
{{end}}
2726

2827
<div class="field footer tw-mx-2">
29-
<span class="markup-info">{{svg "octicon-markdown"}} {{ctx.Locale.Tr "repo.diff.comment.markdown_info"}}</span>
3028
<div class="tw-text-right">
3129
{{if $.reply}}
3230
<button class="ui submit primary tiny button btn-reply" type="submit">{{ctx.Locale.Tr "repo.diff.comment.reply"}}</button>

templates/repo/diff/new_review.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
</div>
1717
<div class="field">
1818
{{template "shared/combomarkdowneditor" (dict
19-
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
20-
"MarkdownPreviewContext" .RepoLink
21-
"TextareaName" "content"
22-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder")
19+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
20+
"TextareaName" "content" "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder")
2321
"DropzoneParentContainer" "form"
2422
)}}
2523
</div>

templates/repo/issue/comment_tab.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
<div class="field">
77
{{template "shared/combomarkdowneditor" (dict
8-
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
9-
"MarkdownPreviewContext" .RepoLink
10-
"TextareaName" "content"
11-
"TextareaContent" $textareaContent
12-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder")
8+
"CustomInit" true
9+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
10+
"TextareaName" "content" "TextareaContent" $textareaContent "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder")
1311
"DropzoneParentContainer" "form, .ui.form"
1412
)}}
1513
</div>

templates/repo/issue/fields/textarea.tmpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
{{if $useMarkdownEditor}}
99
{{template "shared/combomarkdowneditor" (dict
10+
"CustomInit" true
1011
"ContainerClasses" "tw-hidden"
11-
"MarkdownPreviewUrl" (print .root.RepoLink "/markup")
12-
"MarkdownPreviewContext" .root.RepoLink
13-
"TextareaContent" .item.Attributes.value
14-
"TextareaPlaceholder" .item.Attributes.placeholder
12+
"MarkdownPreviewInRepo" $.root.Repository "MarkdownPreviewMode" "comment"
13+
"TextareaContent" .item.Attributes.value "TextareaPlaceholder" .item.Attributes.placeholder
1514
"DropzoneParentContainer" ".combo-editor-dropzone"
1615
)}}
1716

templates/repo/issue/milestone_new.tmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
</div>
3737
<div class="field">
3838
<label>{{ctx.Locale.Tr "repo.milestones.desc"}}</label>
39-
<textarea name="content">{{.content}}</textarea>
39+
{{template "shared/combomarkdowneditor" (dict
40+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
41+
"TextareaName" "content" "TextareaContent" .content
42+
"TextareaPlaceholder" (ctx.Locale.Tr "repo.milestones.desc")
43+
)}}
4044
</div>
41-
<div class="divider"></div>
4245
<div class="tw-text-right">
4346
{{if .PageIsEditMilestone}}
4447
<a class="ui primary basic button" href="{{.RepoLink}}/milestones">

templates/repo/issue/view_content.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@
142142
<div class="ui form comment">
143143
<div class="field">
144144
{{template "shared/combomarkdowneditor" (dict
145-
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
146-
"MarkdownPreviewContext" .RepoLink
145+
"CustomInit" true
146+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
147147
"TextareaName" "content"
148148
"DropzoneParentContainer" ".ui.form"
149149
)}}

templates/repo/release/new.tmpl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@
5050
</div>
5151
<div class="field">
5252
{{template "shared/combomarkdowneditor" (dict
53-
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
54-
"MarkdownPreviewContext" .RepoLink
55-
"TextareaName" "content"
56-
"TextareaContent" .content
57-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.release.message")
58-
"TextareaAriaLabel" (ctx.Locale.Tr "repo.release.message")
53+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "comment"
54+
"TextareaName" "content" "TextareaContent" .content "TextareaPlaceholder" (ctx.Locale.Tr "repo.release.message")
5955
"DropzoneParentContainer" "form"
6056
)}}
6157
</div>

templates/repo/wiki/new.tmpl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@
2323
{{$content = ctx.Locale.Tr "repo.wiki.welcome"}}
2424
{{end}}
2525
{{template "shared/combomarkdowneditor" (dict
26-
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
27-
"MarkdownPreviewContext" .RepoLink
28-
"TextareaName" "content"
29-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.wiki.page_content")
30-
"TextareaAriaLabel" (ctx.Locale.Tr "repo.wiki.page_content")
31-
"TextareaContent" $content
26+
"CustomInit" true
27+
"MarkdownPreviewInRepo" $.Repository "MarkdownPreviewMode" "wiki"
28+
"TextareaName" "content" "TextareaContent" $content "TextareaPlaceholder" (ctx.Locale.Tr "repo.wiki.page_content")
3229
)}}
3330

3431
<div class="field tw-mt-4">

templates/shared/combomarkdowneditor.tmpl

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
{{/*
22
Template Attributes:
3+
* CustomInit: do not initialize the editor automatically
34
* ContainerId: id attribute for the container element
45
* ContainerClasses: additional classes for the container element
5-
* MarkdownPreviewUrl: preview url for the preview tab
6-
* MarkdownPreviewContext: preview context for the preview tab
6+
* MarkdownPreviewInRepo: the repo to preview markdown
7+
* MarkdownPreviewContext: preview context (the related url path when rendering) for the preview tab, eg: repo link or user home link
8+
* MarkdownPreviewMode: content mode for the editor, eg: wiki, comment or default
79
* TextareaName: name attribute for the textarea
810
* TextareaContent: content for the textarea
11+
* TextareaMaxLength: maxlength attribute for the textarea
912
* TextareaPlaceholder: placeholder attribute for the textarea
1013
* TextareaAriaLabel: aria-label attribute for the textarea
1114
* DropzoneParentContainer: container for file upload (leave it empty if no upload)
1215
* DisableAutosize: whether to disable automatic height resizing
1316
*/}}
14-
<div {{if .ContainerId}}id="{{.ContainerId}}"{{end}} class="combo-markdown-editor {{.ContainerClasses}}" data-dropzone-parent-container="{{.DropzoneParentContainer}}">
15-
{{if .MarkdownPreviewUrl}}
17+
{{$ariaLabel := or .TextareaAriaLabel .TextareaPlaceholder}}
18+
{{$repo := .MarkdownPreviewInRepo}}
19+
{{$previewContext := .MarkdownPreviewContext}}
20+
{{$previewMode := .MarkdownPreviewMode}}
21+
{{$previewUrl := print AppSubUrl "/-/markup"}}
22+
{{if $repo}}
23+
{{$previewUrl = print $repo.Link "/markup"}}
24+
{{end}}
25+
{{$supportEasyMDE := or (eq $previewMode "comment") (eq $previewMode "wiki")}}
26+
<div {{if .ContainerId}}id="{{.ContainerId}}"{{end}} class="combo-markdown-editor {{if .CustomInit}}custom-init{{end}} {{.ContainerClasses}}"
27+
data-dropzone-parent-container="{{.DropzoneParentContainer}}"
28+
data-content-mode="{{$previewMode}}" data-support-easy-mde="{{$supportEasyMDE}}"
29+
data-preview-url="{{$previewUrl}}" data-preview-context="{{$previewContext}}"
30+
>
1631
<div class="ui top tabular menu">
1732
<a class="active item" data-tab-for="markdown-writer">{{template "shared/misc/tabtitle" (ctx.Locale.Tr "write")}}</a>
18-
<a class="item" data-tab-for="markdown-previewer" data-preview-url="{{.MarkdownPreviewUrl}}" data-preview-context="{{.MarkdownPreviewContext}}">{{template "shared/misc/tabtitle" (ctx.Locale.Tr "preview")}}</a>
33+
<a class="item" data-tab-for="markdown-previewer">{{template "shared/misc/tabtitle" (ctx.Locale.Tr "preview")}}</a>
1934
</div>
20-
{{end}}
2135
<div class="ui tab active" data-tab-panel="markdown-writer">
2236
<markdown-toolbar>
2337
<div class="markdown-toolbar-group">
@@ -40,17 +54,25 @@ Template Attributes:
4054
<md-task-list class="markdown-toolbar-button" data-tooltip-content="{{ctx.Locale.Tr "editor.buttons.list.task.tooltip"}}">{{svg "octicon-tasklist"}}</md-task-list>
4155
<button class="markdown-toolbar-button markdown-button-table-add" data-tooltip-content="{{ctx.Locale.Tr "editor.buttons.table.add.tooltip"}}">{{svg "octicon-table"}}</button>
4256
</div>
57+
{{if eq $previewMode "comment"}}
4358
<div class="markdown-toolbar-group">
4459
<md-mention class="markdown-toolbar-button" data-tooltip-content="{{ctx.Locale.Tr "editor.buttons.mention.tooltip"}}">{{svg "octicon-mention"}}</md-mention>
4560
<md-ref class="markdown-toolbar-button" data-tooltip-content="{{ctx.Locale.Tr "editor.buttons.ref.tooltip"}}">{{svg "octicon-cross-reference"}}</md-ref>
4661
</div>
62+
{{end}}
4763
<div class="markdown-toolbar-group">
4864
<button class="markdown-toolbar-button markdown-switch-monospace" role="switch" data-enable-text="{{ctx.Locale.Tr "editor.buttons.enable_monospace_font"}}" data-disable-text="{{ctx.Locale.Tr "editor.buttons.disable_monospace_font"}}">{{svg "octicon-typography"}}</button>
65+
{{if $supportEasyMDE}}
4966
<button class="markdown-toolbar-button markdown-switch-easymde" data-tooltip-content="{{ctx.Locale.Tr "editor.buttons.switch_to_legacy.tooltip"}}">{{svg "octicon-arrow-switch"}}</button>
67+
{{end}}
5068
</div>
5169
</markdown-toolbar>
5270
<text-expander keys=": @ #" multiword="#" suffix="">
53-
<textarea class="markdown-text-editor"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}{{if .DisableAutosize}} data-disable-autosize="{{.DisableAutosize}}"{{end}}>{{.TextareaContent}}</textarea>
71+
<textarea class="markdown-text-editor"
72+
{{if .TextareaName}}name="{{.TextareaName}}"{{end}} {{if .TextareaMaxLength}}maxlength="{{.TextareaMaxLength}}"{{end}}
73+
{{if .TextareaPlaceholder}}placeholder="{{.TextareaPlaceholder}}"{{end}} {{if $ariaLabel}}aria-label="{{$ariaLabel}}"{{end}}
74+
{{if .DisableAutosize}}data-disable-autosize="{{.DisableAutosize}}"{{end}}
75+
>{{.TextareaContent}}</textarea>
5476
</text-expander>
5577
<script>
5678
if (localStorage?.getItem('markdown-editor-monospace') === 'true') {

templates/user/settings/profile.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<p id="signed-user-email">{{.SignedUser.Email}}</p>
3030
</div>
3131
<div class="field {{if .Err_Description}}error{{end}}">
32+
{{/* it is rendered as markdown, but the length is limited, so at the moment we do not use the markdown editor here */}}
3233
<label for="description">{{ctx.Locale.Tr "user.user_bio"}}</label>
3334
<textarea id="description" name="description" rows="2" placeholder="{{ctx.Locale.Tr "settings.biography_placeholder"}}" maxlength="255">{{.SignedUser.Description}}</textarea>
3435
</div>

web_src/css/editor/combomarkdowneditor.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
font-size: 0.85em;
9797
}
9898

99+
.combo-markdown-editor .ui.tab.markup[data-tab-panel="markdown-previewer"] {
100+
border-bottom: 1px solid var(--color-secondary);
101+
padding-bottom: 1rem;
102+
}
103+
99104
text-expander {
100105
display: block;
101106
position: relative;

web_src/css/review.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@
123123
padding: 10px 0;
124124
}
125125

126-
.comment-code-cloud .footer .markup-info {
127-
display: inline-block;
128-
margin: 5px 0;
129-
font-size: 12px;
130-
color: var(--color-text-light);
131-
}
132-
133126
.comment-code-cloud .footer .ui.right.floated {
134127
padding-top: 6px;
135128
}

web_src/js/features/common-form.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {applyAreYouSure, initAreYouSure} from '../vendor/jquery.are-you-sure.ts';
22
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.ts';
3+
import {queryElems} from '../utils/dom.ts';
4+
import {initComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
35

46
export function initGlobalFormDirtyLeaveConfirm() {
57
initAreYouSure(window.jQuery);
@@ -13,12 +15,13 @@ export function initGlobalFormDirtyLeaveConfirm() {
1315
export function initGlobalEnterQuickSubmit() {
1416
document.addEventListener('keydown', (e) => {
1517
if (e.key !== 'Enter') return;
18+
const target = e.target as HTMLElement;
1619
const hasCtrlOrMeta = ((e.ctrlKey || e.metaKey) && !e.altKey);
17-
if (hasCtrlOrMeta && e.target.matches('textarea')) {
20+
if (hasCtrlOrMeta && target.matches('textarea')) {
1821
if (handleGlobalEnterQuickSubmit(e.target)) {
1922
e.preventDefault();
2023
}
21-
} else if (e.target.matches('input') && !e.target.closest('form')) {
24+
} else if (target.matches('input') && !target.closest('form')) {
2225
// input in a normal form could handle Enter key by default, so we only handle the input outside a form
2326
// eslint-disable-next-line unicorn/no-lonely-if
2427
if (handleGlobalEnterQuickSubmit(e.target)) {
@@ -27,3 +30,7 @@ export function initGlobalEnterQuickSubmit() {
2730
}
2831
});
2932
}
33+
34+
export function initGlobalComboMarkdownEditor() {
35+
queryElems<HTMLElement>(document, '.combo-markdown-editor:not(.custom-init)', (el) => initComboMarkdownEditor(el));
36+
}

0 commit comments

Comments
 (0)