From e8bfe054d8fcae244a0a2a9b40298e63c4a75667 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 10 Apr 2021 21:54:06 +0200 Subject: [PATCH] Replace easymde with textarea WIP on the easymde replacement. Basically it rips out EasyMDE without much second thought. Issue commenting works but other things may be broken. --- docs/content/page/index.en-us.md | 1 - docs/content/page/index.fr-fr.md | 1 - docs/content/page/index.zh-cn.md | 1 - docs/content/page/index.zh-tw.md | 1 - package-lock.json | 38 +-- package.json | 3 +- routers/repo/commit.go | 1 - routers/repo/compare.go | 1 - routers/repo/editor.go | 4 - routers/repo/issue.go | 3 - routers/repo/pull.go | 1 - routers/repo/release.go | 4 - routers/repo/wiki.go | 4 - templates/base/footer.tmpl | 8 - templates/base/head.tmpl | 6 - templates/repo/editor/edit.tmpl | 8 +- templates/repo/issue/comment_tab.tmpl | 11 +- templates/repo/wiki/new.tmpl | 7 +- templates/shared/markdowntoolbar.tmpl | 21 ++ web_src/js/easymde.js | 8 - web_src/js/features/markdowneditor.js | 97 ++++++ web_src/js/index.js | 394 ++-------------------- web_src/js/utils.js | 10 + web_src/js/utils.test.js | 7 +- web_src/less/_base.less | 17 +- web_src/less/_editor.less | 57 ---- web_src/less/_repository.less | 14 - web_src/less/_review.less | 25 -- web_src/less/features/markdowneditor.less | 22 ++ web_src/less/index.less | 1 + web_src/less/themes/theme-arc-green.less | 96 +----- webpack.config.js | 4 - 32 files changed, 209 insertions(+), 667 deletions(-) create mode 100644 templates/shared/markdowntoolbar.tmpl delete mode 100644 web_src/js/easymde.js create mode 100644 web_src/js/features/markdowneditor.js create mode 100644 web_src/less/features/markdowneditor.less diff --git a/docs/content/page/index.en-us.md b/docs/content/page/index.en-us.md index 98d61576f3d1..583413123959 100644 --- a/docs/content/page/index.en-us.md +++ b/docs/content/page/index.en-us.md @@ -276,7 +276,6 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others. * [DropzoneJS](http://www.dropzonejs.com/) * [Highlight](https://highlightjs.org/) * [Clipboard](https://zenorocha.github.io/clipboard.js/) - * [CodeMirror](https://codemirror.net/) * [jQuery MiniColors](https://github.com/claviska/jquery-minicolors) * Database drivers: * [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) diff --git a/docs/content/page/index.fr-fr.md b/docs/content/page/index.fr-fr.md index 17e22e8b593c..fcabc87bc8dc 100755 --- a/docs/content/page/index.fr-fr.md +++ b/docs/content/page/index.fr-fr.md @@ -263,7 +263,6 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide * [DropzoneJS](http://www.dropzonejs.com/) * [Highlight](https://highlightjs.org/) * [Clipboard](https://zenorocha.github.io/clipboard.js/) - * [CodeMirror](https://codemirror.net/) * [jQuery MiniColors](https://github.com/claviska/jquery-minicolors) * Connecteurs de base de données : * [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) diff --git a/docs/content/page/index.zh-cn.md b/docs/content/page/index.zh-cn.md index cb6a1da793fc..7b93564dfa73 100644 --- a/docs/content/page/index.zh-cn.md +++ b/docs/content/page/index.zh-cn.md @@ -56,7 +56,6 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和 * [DropzoneJS](http://www.dropzonejs.com/) * [Highlight](https://highlightjs.org/) * [Clipboard](https://zenorocha.github.io/clipboard.js/) - * [CodeMirror](https://codemirror.net/) * [jQuery MiniColors](https://github.com/claviska/jquery-minicolors) * 数据库驱动: * [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) diff --git a/docs/content/page/index.zh-tw.md b/docs/content/page/index.zh-tw.md index 488dac16ad57..d096de1894a8 100644 --- a/docs/content/page/index.zh-tw.md +++ b/docs/content/page/index.zh-tw.md @@ -275,7 +275,6 @@ Gitea 是從 [Gogs](http://gogs.io) Fork 出來的,請閱讀部落格文章 [G - [DropzoneJS](http://www.dropzonejs.com/) - [Highlight](https://highlightjs.org/) - [Clipboard](https://zenorocha.github.io/clipboard.js/) - - [CodeMirror](https://codemirror.net/) - [jQuery MiniColors](https://github.com/claviska/jquery-minicolors) - 資料庫驅動程式: - [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) diff --git a/package-lock.json b/package-lock.json index 3777c6b72d4f..d17e3a31b79a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -574,6 +574,11 @@ } } }, + "@github/markdown-toolbar-element": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@github/markdown-toolbar-element/-/markdown-toolbar-element-1.5.1.tgz", + "integrity": "sha512-cb4CHCgTfIfZrxde9DWJH3pBLZC8YSA2xdNg9Eix0DQbaGIvKPGEQ4se0VUyK773GHeIsNgJDocS+VtYmR6xmQ==" + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -2426,19 +2431,6 @@ "q": "^1.1.2" } }, - "codemirror": { - "version": "5.60.0", - "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.60.0.tgz", - "integrity": "sha512-AEL7LhFOlxPlCL8IdTcJDblJm8yrAGib7I+DErJPdZd4l6imx8IMgKK3RblVgBQqz3TZJR4oknQ03bz+uNjBYA==" - }, - "codemirror-spell-checker": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/codemirror-spell-checker/-/codemirror-spell-checker-1.1.2.tgz", - "integrity": "sha1-HGYPkIlIPMtRE7m6nKGcP0mTNx4=", - "requires": { - "typo-js": "*" - } - }, "collect-v8-coverage": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", @@ -3394,16 +3386,6 @@ "resolved": "https://registry.npmjs.org/dropzone/-/dropzone-5.9.2.tgz", "integrity": "sha512-5t2z51DzIsWDbTpwcJIvUlwxBbvcwdCApz0yb9ecKJwG155Xm92KMEZmHW1B0MzoXOKvFwdd0nPu5cpeVcvPHQ==" }, - "easymde": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/easymde/-/easymde-2.14.0.tgz", - "integrity": "sha512-yQh3EF1amknaxDhXE1L28kwknREU8S19o01ki0t6Q8ThECCipXTOM3E/LL32Ia5D3AsCBRbC1/fT5tpLniVGuw==", - "requires": { - "codemirror": "^5.59.2", - "codemirror-spell-checker": "1.1.2", - "marked": "^2.0.0" - } - }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -7668,11 +7650,6 @@ "object-visit": "^1.0.0" } }, - "marked": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/marked/-/marked-2.0.1.tgz", - "integrity": "sha512-5+/fKgMv2hARmMW7DOpykr2iLhl0NgjyELk5yn92iE7z8Se1IS9n3UsFm86hFXIkvMBmVxki8+ckcpjBeyo/hw==" - }, "mathml-tag-names": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/mathml-tag-names/-/mathml-tag-names-2.1.3.tgz", @@ -11796,11 +11773,6 @@ "is-typedarray": "^1.0.0" } }, - "typo-js": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/typo-js/-/typo-js-1.2.0.tgz", - "integrity": "sha512-dELuLBVa2jvWdU/CHTKi2L/POYaRupv942k+vRsFXsM17acXesQGAiGCio82RW7fvcr7bkuD/Zj8XpUh6aPC2A==" - }, "uglify-js": { "version": "3.13.3", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz", diff --git a/package.json b/package.json index 430e98c0799b..99cd4edaa67e 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,13 @@ }, "dependencies": { "@claviska/jquery-minicolors": "2.3.5", + "@github/markdown-toolbar-element": "1.5.1", "@primer/octicons": "12.1.0", "add-asset-webpack-plugin": "2.0.1", "clipboard": "2.0.8", - "codemirror": "5.60.0", "css-loader": "5.2.0", "css-minimizer-webpack-plugin": "1.3.0", "dropzone": "5.9.2", - "easymde": "2.14.0", "esbuild-loader": "2.11.0", "escape-goat": "3.0.0", "fast-glob": "3.2.5", diff --git a/routers/repo/commit.go b/routers/repo/commit.go index c4719526376f..d26990e0cf16 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -261,7 +261,6 @@ func FileHistory(ctx *context.Context) { func Diff(ctx *context.Context) { ctx.Data["PageIsDiff"] = true ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true userName := ctx.Repo.Owner.Name diff --git a/routers/repo/compare.go b/routers/repo/compare.go index 7046f3ecdb60..3184dd4236a8 100644 --- a/routers/repo/compare.go +++ b/routers/repo/compare.go @@ -653,7 +653,6 @@ func CompareDiff(ctx *context.Context) { ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsDiffCompare"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 2cc5c1e7f2fa..33ae5778d47a 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -67,7 +67,6 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["PageIsEdit"] = true ctx.Data["IsNewFile"] = isNewFile ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true canCommit := renderCommitRights(ctx) treePath := cleanUploadFileName(ctx.Repo.TreePath) @@ -189,7 +188,6 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b ctx.Data["PageHasPosted"] = true ctx.Data["IsNewFile"] = isNewFile ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["TreePath"] = form.TreePath ctx.Data["TreeNames"] = treeNames ctx.Data["TreePaths"] = treePaths @@ -533,7 +531,6 @@ func DeleteFilePost(ctx *context.Context) { func UploadFile(ctx *context.Context) { ctx.Data["PageIsUpload"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireSimpleMDE"] = true upload.AddUploadContext(ctx, "repo") canCommit := renderCommitRights(ctx) treePath := cleanUploadFileName(ctx.Repo.TreePath) @@ -569,7 +566,6 @@ func UploadFilePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.UploadRepoFileForm) ctx.Data["PageIsUpload"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireSimpleMDE"] = true upload.AddUploadContext(ctx, "repo") canCommit := renderCommitRights(ctx) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index da3772ef5a69..373220ba99ae 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -772,7 +772,6 @@ func NewIssue(ctx *context.Context) { ctx.Data["PageIsIssueList"] = true ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.Query("title") @@ -937,7 +936,6 @@ func NewIssuePost(ctx *context.Context) { ctx.Data["PageIsIssueList"] = true ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["ReadOnly"] = false ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled @@ -1107,7 +1105,6 @@ func ViewIssue(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 32d11a285b78..d611a8d71868 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -674,7 +674,6 @@ func ViewPullFiles(ctx *context.Context) { setCompareContext(ctx, baseCommit, commit, headTarget) ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil { ctx.ServerError("GetAssignees", err) diff --git a/routers/repo/release.go b/routers/repo/release.go index 2ebb69b6ab08..2695afbb0631 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -212,7 +212,6 @@ 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["RequireTribute"] = true ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch if tagName := ctx.Query("tag"); len(tagName) > 0 { @@ -246,7 +245,6 @@ func NewReleasePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewReleaseForm) ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true - ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true if ctx.HasError() { @@ -349,7 +347,6 @@ 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["RequireTribute"] = true ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "release") @@ -388,7 +385,6 @@ 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 ctx.Data["RequireTribute"] = true tagName := ctx.Params("*") diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 290e2e8bb294..e32c98931327 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -548,7 +548,6 @@ func WikiRaw(ctx *context.Context) { func NewWiki(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireSimpleMDE"] = true if !ctx.Repo.Repository.HasWiki() { ctx.Data["title"] = "Home" @@ -562,7 +561,6 @@ func NewWikiPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewWikiForm) ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireSimpleMDE"] = true if ctx.HasError() { ctx.HTML(http.StatusOK, tplWikiNew) @@ -600,7 +598,6 @@ func NewWikiPost(ctx *context.Context) { func EditWiki(ctx *context.Context) { ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWikiEdit"] = true - ctx.Data["RequireSimpleMDE"] = true if !ctx.Repo.Repository.HasWiki() { ctx.Redirect(ctx.Repo.RepoLink + "/wiki") @@ -620,7 +617,6 @@ func EditWikiPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewWikiForm) ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireSimpleMDE"] = true if ctx.HasError() { ctx.HTML(http.StatusOK, tplWikiNew) diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index bc45315ef9d8..8a75f3d7494e 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -11,14 +11,6 @@ {{template "custom/body_outer_post" .}} {{template "base/footer_content" .}} -{{if .RequireSimpleMDE}} - - - - -{{end}} {{if .RequireU2F}} diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index d8d24c61eac3..a1c1fe369fc1 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -33,9 +33,6 @@ StaticUrlPrefix: '{{StaticUrlPrefix}}', UseServiceWorker: {{UseServiceWorker}}, csrf: '{{.CsrfToken}}', - HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}}, - SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}}, - Tribute: {{if .RequireTribute}}true{{else}}false{{end}}, NotificationSettings: { MinTimeout: {{NotificationSettings.MinTimeout}}, TimeoutStep: {{NotificationSettings.TimeoutStep}}, @@ -64,9 +61,6 @@ -{{if .RequireSimpleMDE}} - -{{end}}