diff options
author | Zettat123 <zettat123@gmail.com> | 2023-02-24 14:36:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 14:36:07 +0800 |
commit | a6175b01d92a75dcbadbbfc6782a486636fd62a2 (patch) | |
tree | f2a285e28d559015bebf1f79e5acc23e03d47b52 | |
parent | 045becf9aacb49554efbe353b47af0e64f2509c5 (diff) | |
download | gitea-a6175b01d92a75dcbadbbfc6782a486636fd62a2.tar.gz gitea-a6175b01d92a75dcbadbbfc6782a486636fd62a2.zip |
Fix nil context in RenderMarkdownToHtml (#23092)
Fix #23082.
This bug is caused by a nil context in
https://github.com/go-gitea/gitea/issues/23082#issuecomment-1441276546 .
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | modules/templates/helper.go | 3 | ||||
-rw-r--r-- | templates/package/content/cargo.tmpl | 2 | ||||
-rw-r--r-- | templates/package/content/chef.tmpl | 2 | ||||
-rw-r--r-- | templates/package/content/npm.tmpl | 2 | ||||
-rw-r--r-- | templates/package/content/pub.tmpl | 2 | ||||
-rw-r--r-- | templates/package/content/pypi.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/issue/comment_tab.tmpl | 10 | ||||
-rw-r--r-- | templates/repo/issue/fields/checkboxes.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/fields/dropdown.tmpl | 6 | ||||
-rw-r--r-- | templates/repo/issue/fields/header.tmpl | 8 | ||||
-rw-r--r-- | templates/repo/issue/fields/input.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/fields/markdown.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/fields/textarea.tmpl | 2 |
13 files changed, 24 insertions, 23 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 4ffd0a5dee..b7bd07670c 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -174,8 +174,9 @@ func NewFuncMap() []template.FuncMap { "RenderEmojiPlain": emoji.ReplaceAliases, "ReactionToEmoji": ReactionToEmoji, "RenderNote": RenderNote, - "RenderMarkdownToHtml": func(input string) template.HTML { + "RenderMarkdownToHtml": func(ctx context.Context, input string) template.HTML { output, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, URLPrefix: setting.AppSubURL, }, input) if err != nil { diff --git a/templates/package/content/cargo.tmpl b/templates/package/content/cargo.tmpl index f78647ca69..410a81d901 100644 --- a/templates/package/content/cargo.tmpl +++ b/templates/package/content/cargo.tmpl @@ -26,7 +26,7 @@ git-fetch-with-cli = true</code></pre></div> {{if or .PackageDescriptor.Metadata.Description .PackageDescriptor.Metadata.Readme}} <h4 class="ui top attached header">{{.locale.Tr "packages.about"}}</h4> {{if .PackageDescriptor.Metadata.Description}}<div class="ui attached segment">{{.PackageDescriptor.Metadata.Description}}</div>{{end}} - {{if .PackageDescriptor.Metadata.Readme}}<div class="ui attached segment">{{RenderMarkdownToHtml .PackageDescriptor.Metadata.Readme}}</div>{{end}} + {{if .PackageDescriptor.Metadata.Readme}}<div class="ui attached segment">{{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.Readme}}</div>{{end}} {{end}} {{if .PackageDescriptor.Metadata.Dependencies}} diff --git a/templates/package/content/chef.tmpl b/templates/package/content/chef.tmpl index edc175f9be..d80ecdf403 100644 --- a/templates/package/content/chef.tmpl +++ b/templates/package/content/chef.tmpl @@ -20,7 +20,7 @@ <h4 class="ui top attached header">{{.locale.Tr "packages.about"}}</h4> <div class="ui attached segment"> {{if .PackageDescriptor.Metadata.Description}}<p>{{.PackageDescriptor.Metadata.Description}}</p>{{end}} - {{if .PackageDescriptor.Metadata.LongDescription}}{{RenderMarkdownToHtml .PackageDescriptor.Metadata.LongDescription}}{{end}} + {{if .PackageDescriptor.Metadata.LongDescription}}{{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.LongDescription}}{{end}} </div> {{end}} diff --git a/templates/package/content/npm.tmpl b/templates/package/content/npm.tmpl index ea514c5263..d0c037b38a 100644 --- a/templates/package/content/npm.tmpl +++ b/templates/package/content/npm.tmpl @@ -25,7 +25,7 @@ <div class="ui attached segment"> {{if .PackageDescriptor.Metadata.Readme}} <div class="markup markdown"> - {{RenderMarkdownToHtml .PackageDescriptor.Metadata.Readme}} + {{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.Readme}} </div> {{else if .PackageDescriptor.Metadata.Description}} {{.PackageDescriptor.Metadata.Description}} diff --git a/templates/package/content/pub.tmpl b/templates/package/content/pub.tmpl index e81439d4da..d5676fca5a 100644 --- a/templates/package/content/pub.tmpl +++ b/templates/package/content/pub.tmpl @@ -14,6 +14,6 @@ {{if or .PackageDescriptor.Metadata.Description .PackageDescriptor.Metadata.Readme}} <h4 class="ui top attached header">{{.locale.Tr "packages.about"}}</h4> {{if .PackageDescriptor.Metadata.Description}}<div class="ui attached segment">{{.PackageDescriptor.Metadata.Description}}</div>{{end}} - {{if .PackageDescriptor.Metadata.Readme}}<div class="ui attached segment">{{RenderMarkdownToHtml .PackageDescriptor.Metadata.Readme}}</div>{{end}} + {{if .PackageDescriptor.Metadata.Readme}}<div class="ui attached segment">{{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.Readme}}</div>{{end}} {{end}} {{end}} diff --git a/templates/package/content/pypi.tmpl b/templates/package/content/pypi.tmpl index 830ba9bd67..8dbed5395e 100644 --- a/templates/package/content/pypi.tmpl +++ b/templates/package/content/pypi.tmpl @@ -16,9 +16,9 @@ <div class="ui attached segment"> <p>{{if .PackageDescriptor.Metadata.Summary}}{{.PackageDescriptor.Metadata.Summary}}{{end}}</p> {{if .PackageDescriptor.Metadata.LongDescription}} - {{RenderMarkdownToHtml .PackageDescriptor.Metadata.LongDescription}} + {{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.LongDescription}} {{else if .PackageDescriptor.Metadata.Description}} - {{RenderMarkdownToHtml .PackageDescriptor.Metadata.Description}} + {{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.Description}} {{end}} </div> {{end}} diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index 86efa8c833..b04a3c6bbb 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -2,15 +2,15 @@ <input type="hidden" name="template-file" value="{{.TemplateFile}}"> {{range .Fields}} {{if eq .Type "input"}} - {{template "repo/issue/fields/input" .}} + {{template "repo/issue/fields/input" Dict "Context" $.Context "item" .}} {{else if eq .Type "markdown"}} - {{template "repo/issue/fields/markdown" .}} + {{template "repo/issue/fields/markdown" Dict "Context" $.Context "item" .}} {{else if eq .Type "textarea"}} - {{template "repo/issue/fields/textarea" .}} + {{template "repo/issue/fields/textarea" Dict "Context" $.Context "item" .}} {{else if eq .Type "dropdown"}} - {{template "repo/issue/fields/dropdown" .}} + {{template "repo/issue/fields/dropdown" Dict "Context" $.Context "item" .}} {{else if eq .Type "checkboxes"}} - {{template "repo/issue/fields/checkboxes" .}} + {{template "repo/issue/fields/checkboxes" Dict "Context" $.Context "item" .}} {{end}} {{end}} {{else}} diff --git a/templates/repo/issue/fields/checkboxes.tmpl b/templates/repo/issue/fields/checkboxes.tmpl index b70334681f..80835b649a 100644 --- a/templates/repo/issue/fields/checkboxes.tmpl +++ b/templates/repo/issue/fields/checkboxes.tmpl @@ -1,7 +1,7 @@ <div class="field"> {{template "repo/issue/fields/header" .}} {{$field := .}} - {{range $i, $opt := .Attributes.options}} + {{range $i, $opt := .item.Attributes.options}} <div class="field"> <div class="ui checkbox"> <input type="checkbox" name="form-field-{{$field.ID}}-{{$i}}" {{if $opt.required}}readonly checked{{end}}> diff --git a/templates/repo/issue/fields/dropdown.tmpl b/templates/repo/issue/fields/dropdown.tmpl index 83c2bb4aac..9adce5602f 100644 --- a/templates/repo/issue/fields/dropdown.tmpl +++ b/templates/repo/issue/fields/dropdown.tmpl @@ -1,12 +1,12 @@ <div class="field"> {{template "repo/issue/fields/header" .}} {{/* FIXME: required validation */}} - <div class="ui fluid selection dropdown {{if .Attributes.multiple}}multiple clearable{{end}}"> - <input type="hidden" name="form-field-{{.ID}}" value="0"> + <div class="ui fluid selection dropdown {{if .item.Attributes.multiple}}multiple clearable{{end}}"> + <input type="hidden" name="form-field-{{.item.ID}}" value="0"> <i class="dropdown icon"></i> <div class="default text"></div> <div class="menu"> - {{range $i, $opt := .Attributes.options}} + {{range $i, $opt := .item.Attributes.options}} <div class="item" data-value="{{$i}}">{{$opt}}</div> {{end}} </div> diff --git a/templates/repo/issue/fields/header.tmpl b/templates/repo/issue/fields/header.tmpl index fb8511b4f0..6034fed5fd 100644 --- a/templates/repo/issue/fields/header.tmpl +++ b/templates/repo/issue/fields/header.tmpl @@ -1,6 +1,6 @@ -{{if .Attributes.label}} - <h3>{{.Attributes.label}}{{if .Validations.required}}<label class="required"></label>{{end}}</h3> +{{if .item.Attributes.label}} + <h3>{{.item.Attributes.label}}{{if .item.Validations.required}}<label class="required"></label>{{end}}</h3> {{end}} -{{if .Attributes.description}} - <span class="help">{{RenderMarkdownToHtml .Attributes.description}}</span> +{{if .item.Attributes.description}} + <span class="help">{{RenderMarkdownToHtml .Context .item.Attributes.description}}</span> {{end}} diff --git a/templates/repo/issue/fields/input.tmpl b/templates/repo/issue/fields/input.tmpl index d73354f6d3..3fc8a86510 100644 --- a/templates/repo/issue/fields/input.tmpl +++ b/templates/repo/issue/fields/input.tmpl @@ -1,4 +1,4 @@ <div class="field"> {{template "repo/issue/fields/header" .}} - <input type="{{if .Validations.is_number}}number{{else}}text{{end}}" name="form-field-{{.ID}}" placeholder="{{.Attributes.placeholder}}" value="{{.Attributes.value}}" {{if .Validations.required}}required{{end}} {{if .Validations.regex}}pattern="{{.Validations.regex}}" title="{{.Validations.regex}}"{{end}}> + <input type="{{if .item.Validations.is_number}}number{{else}}text{{end}}" name="form-field-{{.item.ID}}" placeholder="{{.item.Attributes.placeholder}}" value="{{.item.Attributes.value}}" {{if .item.Validations.required}}required{{end}} {{if .item.Validations.regex}}pattern="{{.item.Validations.regex}}" title="{{.item.Validations.regex}}"{{end}}> </div> diff --git a/templates/repo/issue/fields/markdown.tmpl b/templates/repo/issue/fields/markdown.tmpl index 8236171523..fd5b6afd22 100644 --- a/templates/repo/issue/fields/markdown.tmpl +++ b/templates/repo/issue/fields/markdown.tmpl @@ -1,3 +1,3 @@ <div class="field"> - <div>{{RenderMarkdownToHtml .Attributes.value}}</div> + <div>{{RenderMarkdownToHtml .Context .item.Attributes.value}}</div> </div> diff --git a/templates/repo/issue/fields/textarea.tmpl b/templates/repo/issue/fields/textarea.tmpl index 5ad82e2460..4b390fc9d6 100644 --- a/templates/repo/issue/fields/textarea.tmpl +++ b/templates/repo/issue/fields/textarea.tmpl @@ -2,5 +2,5 @@ {{template "repo/issue/fields/header" .}} {{/* FIXME: preview markdown result */}} {{/* FIXME: required validation for markdown editor */}} - <textarea name="form-field-{{.ID}}" placeholder="{{.Attributes.placeholder}}" class="edit_area {{if .Attributes.render}}no-easymde{{end}}" {{if and .Validations.required .Attributes.render}}required{{end}}>{{.Attributes.value}}</textarea> + <textarea name="form-field-{{.item.ID}}" placeholder="{{.item.Attributes.placeholder}}" class="edit_area {{if .item.Attributes.render}}no-easymde{{end}}" {{if and .item.Validations.required .item.Attributes.render}}required{{end}}>{{.item.Attributes.value}}</textarea> </div> |