Skip to content

Commit

Permalink
added json_inline helper
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Feb 24, 2023
1 parent 8f1608d commit 59b3f68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Render(template string, def parser.Definition, params map[string]interface{
ctx.Set("def", def)
ctx.Set("params", params)
ctx.Set("json", toJSONHelper)
ctx.Set("json_inline", toJSONInlineHelper)
ctx.Set("format_comment_line", formatCommentLine)
ctx.Set("format_comment_text", formatCommentText)
ctx.Set("format_comment_html", formatCommentHTML)
Expand All @@ -43,6 +44,14 @@ func toJSONHelper(v interface{}) (template.HTML, error) {
return template.HTML(b), nil
}

func toJSONInlineHelper(v interface{}) (template.HTML, error) {
b, err := json.Marshal(v)
if err != nil {
return "", err
}
return template.HTML(b), nil
}

func formatCommentLine(s string) template.HTML {
var buf bytes.Buffer
doc.ToText(&buf, s, "", "", 2000)
Expand Down

0 comments on commit 59b3f68

Please sign in to comment.