Skip to content

Commit c9e582c

Browse files
Refactor markdown editor and use it for milestone description editor (#32688)
Refactor markdown editor to clarify its "preview" behavior and remove jQuery code. Close #15045 --------- Co-authored-by: silverwind <[email protected]>
1 parent 2f43536 commit c9e582c

29 files changed

+147
-116
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
@@ -2590,7 +2590,6 @@ diff.generated = generated
25902590
diff.vendored = vendored
25912591
diff.comment.add_line_comment = Add line comment
25922592
diff.comment.placeholder = Leave a comment
2593-
diff.comment.markdown_info = Styling with markdown is supported.
25942593
diff.comment.add_single_comment = Add single comment
25952594
diff.comment.add_review_comment = Add comment
25962595
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
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
25+
"MarkdownPreviewContext" (Iif $.Repository "" .HomeLink)
26+
"MarkdownPreviewMode" (Iif $.Repository "comment")
27+
"TextareaName" "content"
28+
"TextareaContent" .content
29+
"TextareaPlaceholder" (ctx.Locale.Tr "repo.projects.description_placeholder")
30+
)}}
2231
</div>
2332

2433
{{if not .PageIsEditProjects}}

templates/repo/diff/box.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@
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
245+
"MarkdownPreviewMode" "comment"
245246
"TextareaName" "content"
246247
"DropzoneParentContainer" ".ui.form"
247248
)}}

templates/repo/diff/comment_form.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
<input type="hidden" name="diff_start_cid">
1010
<input type="hidden" name="diff_end_cid">
1111
<input type="hidden" name="diff_base_cid">
12-
12+
<div class="field">
1313
{{template "shared/combomarkdowneditor" (dict
14-
"MarkdownPreviewUrl" (print $.root.Repository.Link "/markup")
15-
"MarkdownPreviewContext" $.root.RepoLink
14+
"CustomInit" true
15+
"MarkdownPreviewInRepo" $.root.Repository
16+
"MarkdownPreviewMode" "comment"
1617
"TextareaName" "content"
1718
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder")
1819
"DropzoneParentContainer" "form"
1920
"DisableAutosize" "true"
2021
)}}
21-
22+
</div>
2223
{{if $.root.IsAttachmentEnabled}}
2324
<div class="field">
2425
{{template "repo/upload" $.root}}
2526
</div>
2627
{{end}}
2728

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

0 commit comments

Comments
 (0)