diff options
author | Brecht Van Lommel <brecht@blender.org> | 2023-03-24 07:12:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 14:12:23 +0800 |
commit | 84daddc2fa74393cdc13371b0cc44f0444cfdae0 (patch) | |
tree | eaf75d3173ee67d65288accef86bbb7c6c08535e /templates | |
parent | 9e04627acaaa853e5269f98f53f2615077cfb028 (diff) | |
download | gitea-84daddc2fa74393cdc13371b0cc44f0444cfdae0.tar.gz gitea-84daddc2fa74393cdc13371b0cc44f0444cfdae0.zip |
Editor preview support for external renderers (#23333)
Remove `[repository.editor] PREVIEWABLE_FILE_MODES` setting that seemed
like it was intended to support this but did not work. Instead, whenever
viewing a file shows a preview, also have a Preview tab in the file
editor.
Add new `/markup` web and API endpoints with `comment`, `gfm`,
`markdown` and new `file` mode that uses a file path to determine the
renderer.
Remove `/markdown` web endpoint but keep the API for backwards and
GitHub compatibility.
## ⚠️ BREAKING ⚠️
The `[repository.editor] PREVIEWABLE_FILE_MODES` setting was removed.
This setting served no practical purpose and was not working correctly.
Instead a preview tab is always shown in the file editor when supported.
---------
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'templates')
-rw-r--r-- | templates/repo/diff/box.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/diff/comment_form.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/editor/edit.tmpl | 6 | ||||
-rw-r--r-- | templates/repo/issue/comment_tab.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/issue/view_content.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/release/new.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/wiki/new.tmpl | 4 | ||||
-rw-r--r-- | templates/swagger/v1_json.tmpl | 67 |
8 files changed, 77 insertions, 12 deletions
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 6dafe6f896..8926c518ae 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -192,7 +192,7 @@ <div class="ui comment form"> <div class="ui top attached tabular menu"> <a class="active write item">{{$.locale.Tr "write"}}</a> - <a class="preview item" data-url="{{$.Repository.Link}}/markdown" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> + <a class="preview item" data-url="{{$.Repository.Link}}/markup" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> </div> <div class="ui bottom attached active write tab segment"> <textarea class="review-textarea js-quick-submit" tabindex="1" name="content"></textarea> diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 225e40f7f0..deea6baffb 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -11,7 +11,7 @@ <input type="hidden" name="diff_base_cid"> <div class="ui top tabular menu" data-write="write" data-preview="preview"> <a class="active item" data-tab="write">{{$.root.locale.Tr "write"}}</a> - <a class="item" data-tab="preview" data-url="{{$.root.Repository.Link}}/markdown" data-context="{{$.root.RepoLink}}">{{$.root.locale.Tr "preview"}}</a> + <a class="item" data-tab="preview" data-url="{{$.root.Repository.Link}}/markup" data-context="{{$.root.RepoLink}}">{{$.root.locale.Tr "preview"}}</a> </div> <div class="field"> <div class="ui active tab" data-tab="write"> diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index 19c5cb007a..737027f590 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -31,15 +31,15 @@ <div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff"> <a class="active item" data-tab="write">{{svg "octicon-code"}} {{if .IsNewFile}}{{.locale.Tr "repo.editor.new_file"}}{{else}}{{.locale.Tr "repo.editor.edit_file"}}{{end}}</a> {{if not .IsNewFile}} - <a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markdown" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-preview-file-modes="{{.PreviewableFileModes}}" data-markdown-mode="gfm">{{svg "octicon-eye"}} {{.locale.Tr "preview"}}</a> + <a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-eye"}} {{.locale.Tr "preview"}}</a> <a class="item" data-tab="diff" data-url="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}" data-context="{{.BranchLink}}">{{svg "octicon-diff"}} {{.locale.Tr "repo.editor.preview_changes"}}</a> {{end}} </div> <div class="ui bottom attached active tab segment" data-tab="write"> <textarea id="edit_area" name="content" class="gt-hidden" data-id="repo-{{.Repository.Name}}-{{.TreePath}}" - data-url="{{.Repository.Link}}/markdown" + data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}" - data-markdown-file-exts="{{.MarkdownFileExts}}" + data-previewable-extensions="{{.PreviewableExtensions}}" data-line-wrap-extensions="{{.LineWrapExtensions}}"> {{.FileContent}}</textarea> <div class="editor-loading is-loading"></div> diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index b8e8d2d9aa..47d6ca9587 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -1,10 +1,10 @@ <div class="ui top tabular menu" data-write="write" data-preview="preview"> <a class="active item" data-tab="write">{{.locale.Tr "write"}}</a> - <a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markdown" data-context="{{.RepoLink}}">{{.locale.Tr "preview"}}</a> + <a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}">{{.locale.Tr "preview"}}</a> </div> <div class="field"> <div class="ui bottom active tab" data-tab="write"> - <textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.Link}}/markdown" data-context="{{.Repo.RepoLink}}"> + <textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.Link}}/markup" data-context="{{.Repo.RepoLink}}"> {{- if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end -}} </textarea> </div> diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 3e43701b63..8a55d4e30e 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -168,7 +168,7 @@ <div class="ui comment form"> <div class="ui top tabular menu"> <a class="active write item">{{$.locale.Tr "write"}}</a> - <a class="preview item" data-url="{{$.Repository.Link}}/markdown" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> + <a class="preview item" data-url="{{$.Repository.Link}}/markup" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> </div> <div class="field"> <div class="ui bottom active tab write"> diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 8c4df98d19..692a373dc6 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -53,7 +53,7 @@ <label>{{.locale.Tr "repo.release.content"}}</label> <div class="ui top tabular menu" data-write="write" data-preview="preview"> <a class="active write item" data-tab="write">{{$.locale.Tr "write"}}</a> - <a class="preview item" data-tab="preview" data-url="{{$.Repository.Link}}/markdown" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> + <a class="preview item" data-tab="preview" data-url="{{$.Repository.Link}}/markup" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> </div> <div class="ui bottom active tab" data-tab="write"> <textarea name="content">{{.content}}</textarea> diff --git a/templates/repo/wiki/new.tmpl b/templates/repo/wiki/new.tmpl index 9e9de99022..085af4cbc9 100644 --- a/templates/repo/wiki/new.tmpl +++ b/templates/repo/wiki/new.tmpl @@ -21,11 +21,11 @@ </div> <div class="ui top attached tabular menu previewtabs" data-write="write" data-preview="preview"> <a class="active item" data-tab="write">{{.locale.Tr "write"}}</a> - <a class="item" data-tab="preview" data-url="{{$.Repository.Link}}/markdown" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> + <a class="item" data-tab="preview" data-url="{{$.Repository.Link}}/markup" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a> </div> <div class="field content" data-loading="{{.locale.Tr "loading"}}"> <div class="ui bottom active tab" data-tab="write"> - <textarea class="js-quick-submit" id="edit_area" name="content" data-id="wiki-{{.title}}" data-url="{{.Repository.Link}}/markdown" data-context="{{.RepoLink}}">{{if .PageIsWikiEdit}}{{.content}}{{else}}{{.locale.Tr "repo.wiki.welcome"}}{{end}}</textarea> + <textarea class="js-quick-submit" id="edit_area" name="content" data-id="wiki-{{.title}}" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}">{{if .PageIsWikiEdit}}{{.content}}{{else}}{{.locale.Tr "repo.wiki.welcome"}}{{end}}</textarea> </div> </div> <div class="field"> diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index ddcdc94b81..0f7e60c598 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -951,6 +951,38 @@ } } }, + "/markup": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "text/html" + ], + "tags": [ + "miscellaneous" + ], + "summary": "Render a markup document as HTML", + "operationId": "renderMarkup", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "$ref": "#/definitions/MarkupOption" + } + } + ], + "responses": { + "200": { + "$ref": "#/responses/MarkupRender" + }, + "422": { + "$ref": "#/responses/validationError" + } + } + } + }, "/nodeinfo": { "get": { "produces": [ @@ -17991,7 +18023,7 @@ "type": "string" }, "Mode": { - "description": "Mode to render\n\nin: body", + "description": "Mode to render (comment, gfm, markdown)\n\nin: body", "type": "string" }, "Text": { @@ -18005,6 +18037,33 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "MarkupOption": { + "description": "MarkupOption markup options", + "type": "object", + "properties": { + "Context": { + "description": "Context to render\n\nin: body", + "type": "string" + }, + "FilePath": { + "description": "File path for detecting extension in file mode\n\nin: body", + "type": "string" + }, + "Mode": { + "description": "Mode to render (comment, gfm, markdown, file)\n\nin: body", + "type": "string" + }, + "Text": { + "description": "Text markup to render\n\nin: body", + "type": "string" + }, + "Wiki": { + "description": "Is it a wiki page ?\n\nin: body", + "type": "boolean" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "MergePullRequestOption": { "description": "MergePullRequestForm form for merging Pull Request", "type": "object", @@ -20835,6 +20894,12 @@ "type": "string" } }, + "MarkupRender": { + "description": "MarkupRender is a rendered markup document", + "schema": { + "type": "string" + } + }, "Milestone": { "description": "Milestone", "schema": { |