From dde8487de595a7611be4ee54dd9c0f65d373b1a9 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 19 Feb 2021 16:29:46 +0800 Subject: [PATCH 1/2] Add easyMDE(simpleMDE) support for release content editor Signed-off-by: a1012112796 <1012112796@qq.com> --- routers/repo/release.go | 4 ++++ templates/repo/release/new.tmpl | 13 +++++++++++-- web_src/js/index.js | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/routers/repo/release.go b/routers/repo/release.go index 54642f9b210a0..eeca58932e3af 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -210,6 +210,7 @@ func LatestRelease(ctx *context.Context) { func NewRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true + ctx.Data["RequireSimpleMDE"] = true ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch if tagName := ctx.Query("tag"); len(tagName) > 0 { rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) @@ -235,6 +236,7 @@ func NewReleasePost(ctx *context.Context) { form := web.GetForm(ctx).(*auth.NewReleaseForm) ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true + ctx.Data["RequireSimpleMDE"] = true if ctx.HasError() { ctx.HTML(200, tplReleaseNew) @@ -313,6 +315,7 @@ func EditRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true + ctx.Data["RequireSimpleMDE"] = true ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "release") @@ -343,6 +346,7 @@ func EditReleasePost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true + ctx.Data["RequireSimpleMDE"] = true tagName := ctx.Params("*") rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 98b6a2095f6b4..473257a2107b8 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -44,9 +44,18 @@ -
+
- + +
+ +
+
+ {{$.i18n.Tr "loading"}} +
{{if .IsAttachmentEnabled}}
diff --git a/web_src/js/index.js b/web_src/js/index.js index c67b3c809bb2f..2f328d72e57ba 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1734,6 +1734,20 @@ async function initEditor() { }); } +function initReleaseEditor() { + const $editor = $('.repository.new.release .content-editor'); + if ($editor.length === 0) { + return false; + } + + const $textarea = $editor.find('textarea'); + attachTribute($textarea.get(), {mentions: false, emoji: true}); + const $files = $editor.parent().find('.files'); + const $simplemde = setCommentSimpleMDE($textarea); + initCommentPreviewTab($editor); + initSimpleMDEImagePaste($simplemde, $files); +} + function initOrganization() { if ($('.organization').length === 0) { return; @@ -2623,6 +2637,7 @@ $(document).ready(async () => { initTableSort(); initNotificationsTable(); initPullRequestMergeInstruction(); + initReleaseEditor(); const routes = { 'div.user.settings': initUserSettings, From 1fca134d4a6eaf53564e9410cb9562e1c02f00b3 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 20 Feb 2021 15:24:07 +0800 Subject: [PATCH 2/2] RequireTribute --- routers/repo/release.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/repo/release.go b/routers/repo/release.go index eeca58932e3af..b4370bb09b960 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -211,6 +211,7 @@ func NewRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["RequireSimpleMDE"] = true + ctx.Data["RequireTribute"] = true ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch if tagName := ctx.Query("tag"); len(tagName) > 0 { rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) @@ -237,6 +238,7 @@ func NewReleasePost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["RequireSimpleMDE"] = true + ctx.Data["RequireTribute"] = true if ctx.HasError() { ctx.HTML(200, tplReleaseNew) @@ -316,6 +318,7 @@ func EditRelease(ctx *context.Context) { ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true ctx.Data["RequireSimpleMDE"] = true + ctx.Data["RequireTribute"] = true ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "release") @@ -347,6 +350,7 @@ func EditReleasePost(ctx *context.Context) { ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true ctx.Data["RequireSimpleMDE"] = true + ctx.Data["RequireTribute"] = true tagName := ctx.Params("*") rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)