-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support markdown editor for issue template #24400
Merged
silverwind
merged 19 commits into
go-gitea:main
from
yp05327:support-markdown-editor-in-issue-tmpl
May 8, 2023
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1bdb4e8
wip
yp05327 df498c7
fix tmpl
yp05327 759c9f7
remove upload
yp05327 ce9ce24
reuse textarea
yp05327 ff6146a
convert to listen focus event
yp05327 2db0fb4
add default value
yp05327 f39e26f
fix lint
yp05327 3bb0557
fix placeholder
yp05327 ff83b3b
improve
yp05327 f26e1c9
improve
yp05327 30e814b
Merge branch 'main' into support-markdown-editor-in-issue-tmpl
wxiaoguang ce56040
fix
wxiaoguang 143dcad
fix
wxiaoguang ed80115
Merge branch 'main' into support-markdown-editor-in-issue-tmpl
wxiaoguang 4c58d89
Merge branch 'main' into support-markdown-editor-in-issue-tmpl
wxiaoguang 7ddd020
Merge branch 'main' into support-markdown-editor-in-issue-tmpl
yp05327 49b0046
fix
yp05327 d22b77f
rename TributeExpander to TextExpander
silverwind 9d128c5
Merge branch 'main' into support-markdown-editor-in-issue-tmpl
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
<div class="field"> | ||
{{$useMarkdownEditor := not .item.Attributes.render}} | ||
<div class="field {{if $useMarkdownEditor}}combo-editor-dropzone{{end}}"> | ||
{{template "repo/issue/fields/header" .}} | ||
{{/* FIXME: preview markdown result */}} | ||
{{/* FIXME: required validation for markdown editor */}} | ||
<textarea name="form-field-{{.item.ID}}" placeholder="{{.item.Attributes.placeholder}}" {{if and .item.Validations.required .item.Attributes.render}}required{{end}}>{{.item.Attributes.value}}</textarea> | ||
|
||
{{/* the real form element to provide the value */}} | ||
<textarea class="form-field-real" name="form-field-{{.item.ID}}" placeholder="{{.item.Attributes.placeholder}}" {{if and .item.Validations.required}}required{{end}}>{{.item.Attributes.value}}</textarea> | ||
|
||
{{if $useMarkdownEditor}} | ||
{{template "shared/combomarkdowneditor" (dict | ||
"locale" .root.locale | ||
"ContainerClasses" "gt-hidden" | ||
"MarkdownPreviewUrl" (print .root.RepoLink "/markup") | ||
"MarkdownPreviewContext" .root.RepoLink | ||
"TextareaContent" .item.Attributes.value | ||
"TextareaPlaceholder" .item.Attributes.placeholder | ||
"DropzoneParentContainer" ".combo-editor-dropzone" | ||
)}} | ||
|
||
{{if .root.IsAttachmentEnabled}} | ||
<div class="gt-mt-4 form-field-dropzone gt-hidden"> | ||
{{template "repo/upload" .root}} | ||
</div> | ||
{{end}} | ||
{{end}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {matchEmoji, matchMention} from '../../utils/match.js'; | ||
import {emojiString} from '../emoji.js'; | ||
|
||
export function initTextExpander(expander) { | ||
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => { | ||
if (key === ':') { | ||
const matches = matchEmoji(text); | ||
if (!matches.length) return provide({matched: false}); | ||
|
||
const ul = document.createElement('ul'); | ||
ul.classList.add('suggestions'); | ||
for (const name of matches) { | ||
const emoji = emojiString(name); | ||
const li = document.createElement('li'); | ||
li.setAttribute('role', 'option'); | ||
li.setAttribute('data-value', emoji); | ||
li.textContent = `${emoji} ${name}`; | ||
ul.append(li); | ||
} | ||
|
||
provide({matched: true, fragment: ul}); | ||
} else if (key === '@') { | ||
const matches = matchMention(text); | ||
if (!matches.length) return provide({matched: false}); | ||
|
||
const ul = document.createElement('ul'); | ||
ul.classList.add('suggestions'); | ||
for (const {value, name, fullname, avatar} of matches) { | ||
const li = document.createElement('li'); | ||
li.setAttribute('role', 'option'); | ||
li.setAttribute('data-value', `${key}${value}`); | ||
|
||
const img = document.createElement('img'); | ||
img.src = avatar; | ||
li.append(img); | ||
|
||
const nameSpan = document.createElement('span'); | ||
nameSpan.textContent = name; | ||
li.append(nameSpan); | ||
|
||
if (fullname && fullname.toLowerCase() !== name) { | ||
const fullnameSpan = document.createElement('span'); | ||
fullnameSpan.classList.add('fullname'); | ||
fullnameSpan.textContent = fullname; | ||
li.append(fullnameSpan); | ||
} | ||
|
||
ul.append(li); | ||
} | ||
|
||
provide({matched: true, fragment: ul}); | ||
} | ||
}); | ||
expander?.addEventListener('text-expander-value', ({detail}) => { | ||
if (detail?.item) { | ||
detail.value = detail.item.getAttribute('data-value'); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only side effect is: if there is no
textarea
in template, then no uploader. IMO it's acceptable.(it could also be easily fixed by: if no textarea, then add the "uploader" in the end, feel free to do so or not )