From 861521a9c48f6ba2f9b78e42386c031be0d8e1bf Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 24 Oct 2023 16:02:14 +0200 Subject: [PATCH 1/5] Use Markdowneditor on more places in Gitea --- options/locale/locale_en-US.ini | 2 +- routers/web/org/projects.go | 13 ++++++++----- routers/web/repo/projects.go | 8 ++++++++ routers/web/web.go | 2 ++ templates/org/settings/options.tmpl | 12 ++++++++++-- templates/projects/new.tmpl | 12 ++++++++++-- templates/repo/issue/fields/textarea.tmpl | 2 +- templates/shared/combomarkdowneditor.tmpl | 11 ++++++++--- templates/user/settings/profile.tmpl | 13 +++++++++++-- web_src/js/features/comp/ComboMarkdownEditor.js | 2 +- web_src/js/features/misc.js | 9 +++++++++ web_src/js/index.js | 3 +++ 12 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 web_src/js/features/misc.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b0c21816ae936..2ee9b39955a3b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -636,7 +636,7 @@ uid = UID webauthn = Security Keys public_profile = Public Profile -biography_placeholder = Tell us a little bit about yourself! (You can use Markdown) +biography_placeholder = Tell us a little bit about yourself! location_placeholder = Share your approximate location with others profile_desc = Control how your profile is show to other users. Your primary email address will be used for notifications, password recovery and web-based Git operations. password_username_disabled = Non-local users are not allowed to change their username. Please contact your site administrator for more details. diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 439fdf644bb6a..4921dcd5acf4c 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -99,10 +99,6 @@ func Projects(ctx *context.Context) { ctx.Data["State"] = "open" } - for _, project := range projects { - project.RenderedContent = project.Description - } - err = shared_user.LoadHeaderCount(ctx) if err != nil { ctx.ServerError("LoadHeaderCount", err) @@ -142,6 +138,10 @@ func RenderNewProject(ctx *context.Context) { ctx.Data["PageIsViewProjects"] = true ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() ctx.Data["CancelLink"] = ctx.ContextUser.HomeLink() + "/-/projects" + ctx.Data["ProjectMarkdownPreviewURL"] = fmt.Sprintf("%s/-/markup", ctx.ContextUser.HomeLink()) + ctx.Data["ProjectMarkdownPreviewContext"] = ctx.ContextUser.HomeLink() + ctx.Data["ProjectMarkdownPreviewMode"] = "markdown" + ctx.Data["ProjectMarkdownHideRepoButtons"] = true shared_user.RenderUserHeader(ctx) err := shared_user.LoadHeaderCount(ctx) @@ -268,6 +268,10 @@ func RenderEditProject(ctx *context.Context) { ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() ctx.Data["card_type"] = p.CardType ctx.Data["CancelLink"] = fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), p.ID) + ctx.Data["ProjectMarkdownPreviewURL"] = fmt.Sprintf("%s/-/markup", ctx.ContextUser.HomeLink()) + ctx.Data["ProjectMarkdownPreviewContext"] = ctx.ContextUser.HomeLink() + ctx.Data["ProjectMarkdownPreviewMode"] = "markdown" + ctx.Data["ProjectMarkdownHideRepoButtons"] = true ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -391,7 +395,6 @@ func ViewProject(ctx *context.Context) { } } - project.RenderedContent = project.Description ctx.Data["LinkedPRs"] = linkedPrsMap ctx.Data["PageIsViewProjects"] = true ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 6417024f8ba3c..24d6bde9c9211 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -129,6 +129,10 @@ func RenderNewProject(ctx *context.Context) { ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["CancelLink"] = ctx.Repo.Repository.Link() + "/projects" + ctx.Data["ProjectMarkdownPreviewURL"] = fmt.Sprintf("%s/markup", ctx.Repo.Repository.Link()) + ctx.Data["ProjectMarkdownPreviewContext"] = ctx.Repo.Repository.Link() + ctx.Data["ProjectMarkdownPreviewMode"] = "comment" + ctx.Data["ProjectMarkdownHideRepoButtons"] = false ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -236,6 +240,10 @@ func RenderEditProject(ctx *context.Context) { ctx.Data["card_type"] = p.CardType ctx.Data["redirect"] = ctx.FormString("redirect") ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), p.ID) + ctx.Data["ProjectMarkdownPreviewURL"] = fmt.Sprintf("%s/markup", ctx.Repo.Repository.Link()) + ctx.Data["ProjectMarkdownPreviewContext"] = ctx.Repo.Repository.Link() + ctx.Data["ProjectMarkdownPreviewMode"] = "comment" + ctx.Data["ProjectMarkdownHideRepoButtons"] = false ctx.HTML(http.StatusOK, tplProjectsNew) } diff --git a/routers/web/web.go b/routers/web/web.go index 6449f7716cf75..15b9a4b372c7a 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -923,6 +923,8 @@ func registerRoutes(m *web.Route) { }, reqSignIn) m.Group("/{username}/-", func() { + m.Post("/markup", web.Bind(structs.MarkupOption{}), misc.Markup) + if setting.Packages.Enabled { m.Group("/packages", func() { m.Get("", user.ListPackages) diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 31c0d85d89eda..df2a770b6b3c8 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -22,9 +22,17 @@ -
+
- + {{template "shared/combomarkdowneditor" (dict + "MarkdownPreviewUrl" (printf "%s/-/markup" .Org.HomeLink) + "MarkdownPreviewContext" .Org.HomeLink + "MarkdownPreviewMode" "markdown" + "TextareaName" "description" + "TextareaContent" .Org.Description + "TextareaMaxLength" 255 + "HideRepoButtons" true + )}}
diff --git a/templates/projects/new.tmpl b/templates/projects/new.tmpl index 711dbe842ac45..b613d08346f9d 100644 --- a/templates/projects/new.tmpl +++ b/templates/projects/new.tmpl @@ -16,9 +16,17 @@
-
+
- + {{template "shared/combomarkdowneditor" (dict + "MarkdownPreviewUrl" $.ProjectMarkdownPreviewURL + "MarkdownPreviewContext" $.ProjectMarkdownPreviewContext + "MarkdownPreviewMode" $.ProjectMarkdownPreviewMode + "TextareaName" "content" + "TextareaContent" .content + "TextareaPlaceholder" (ctx.Locale.Tr "repo.projects.description_placeholder") + "HideRepoButtons" $.ProjectMarkdownHideRepoButtons + )}}
{{if not .PageIsEditProjects}} diff --git a/templates/repo/issue/fields/textarea.tmpl b/templates/repo/issue/fields/textarea.tmpl index 55adeb28d08f4..56585bcaca2f1 100644 --- a/templates/repo/issue/fields/textarea.tmpl +++ b/templates/repo/issue/fields/textarea.tmpl @@ -9,7 +9,7 @@ {{template "shared/combomarkdowneditor" (dict "ContainerClasses" "gt-hidden" "MarkdownPreviewUrl" (print .root.RepoLink "/markup") - "MarkdownPreviewContext" .root.RepoLink + "MarkdownPreviewContextg" .root.RepoLink "TextareaContent" .item.Attributes.value "TextareaPlaceholder" .item.Attributes.placeholder "DropzoneParentContainer" ".combo-editor-dropzone" diff --git a/templates/shared/combomarkdowneditor.tmpl b/templates/shared/combomarkdowneditor.tmpl index c6e86133cdf45..7ff69a962c97d 100644 --- a/templates/shared/combomarkdowneditor.tmpl +++ b/templates/shared/combomarkdowneditor.tmpl @@ -3,19 +3,22 @@ Template Attributes: * ContainerId: id attribute for the container element * ContainerClasses: additional classes for the container element * MarkdownPreviewUrl: preview url for the preview tab +* MarkdownPreviewMode: the preview mode (default to comment) * MarkdownPreviewContext: preview context for the preview tab * TextareaName: name attribute for the textarea * TextareaContent: content for the textarea * TextareaPlaceholder: placeholder attribute for the textarea * TextareaAriaLabel: aria-label attribute for the textarea +* TextareaMaxLength: maxlength attribute for the textarea * DropzoneParentContainer: container for file upload (leave it empty if no upload) * DisableAutosize: whether to disable automatic height resizing +* HideRepoButtons: hide buttons that belongs to a repo */}}
{{if .MarkdownPreviewUrl}} {{end}}
@@ -37,7 +40,9 @@ Template Attributes:
{{svg "octicon-mention"}} - {{svg "octicon-cross-reference"}} + {{if not .HideRepoButtons}} + {{svg "octicon-cross-reference"}} + {{end}}
@@ -45,7 +50,7 @@ Template Attributes:
- +