hardfix imgvar
This commit is contained in:
parent
cb2df810ed
commit
1a7a15f478
@ -73,13 +73,27 @@ var tmplFuncs = template.FuncMap{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RenderImage(content string) template.HTML {
|
func RenderImage(content string) template.HTML {
|
||||||
var res model.ImageContent
|
contents := strings.Split(content, "`,`")
|
||||||
err := json.Unmarshal([]byte(content), &res)
|
var builder strings.Builder
|
||||||
if err != nil {
|
|
||||||
return SplitContent(content)
|
for i, cnt := range contents {
|
||||||
|
if i == 0 {
|
||||||
|
cnt = strings.TrimPrefix(cnt, "`")
|
||||||
|
}
|
||||||
|
if i == len(contents)-1 {
|
||||||
|
cnt = strings.TrimSuffix(cnt, "`")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res model.ImageContent
|
||||||
|
err := json.Unmarshal([]byte(cnt), &res)
|
||||||
|
if err != nil {
|
||||||
|
return SplitContent(content)
|
||||||
|
} else {
|
||||||
|
builder.WriteString(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, res.Image))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tpl := template.HTML(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, res.Image))
|
|
||||||
return tpl
|
return template.HTML(builder.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func SplitContent(content string) template.HTML {
|
func SplitContent(content string) template.HTML {
|
||||||
|
Loading…
Reference in New Issue
Block a user