Skip to content
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

Fix nil context in RenderMarkdownToHtml #23092

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion templates/package/content/cargo.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/package/content/chef.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
2 changes: 1 addition & 1 deletion templates/package/content/npm.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/package/content/pub.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
4 changes: 2 additions & 2 deletions templates/package/content/pypi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
10 changes: 5 additions & 5 deletions templates/repo/issue/comment_tab.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/fields/checkboxes.tmpl
Original file line number Diff line number Diff line change
@@ -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}}>
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/issue/fields/dropdown.tmpl
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
8 changes: 4 additions & 4 deletions templates/repo/issue/fields/header.tmpl
Original file line number Diff line number Diff line change
@@ -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}}
2 changes: 1 addition & 1 deletion templates/repo/issue/fields/input.tmpl
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion templates/repo/issue/fields/markdown.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="field">
<div>{{RenderMarkdownToHtml .Attributes.value}}</div>
<div>{{RenderMarkdownToHtml .Context .item.Attributes.value}}</div>
</div>
2 changes: 1 addition & 1 deletion templates/repo/issue/fields/textarea.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>