-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheval_v_html.go
More file actions
45 lines (36 loc) · 995 Bytes
/
Copy patheval_v_html.go
File metadata and controls
45 lines (36 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package vuego
import (
"fmt"
"strings"
"golang.org/x/net/html"
"github.com/titpetric/vuego/internal/helpers"
)
func (v *Vue) evalVHtml(ctx VueContext, n *html.Node) error {
expr := helpers.GetAttr(n, "v-html")
if expr == "" {
return nil
}
val, ok := ctx.stack.Resolve(expr)
if !ok {
// v-html may be a function call like "file(src)"
var err error
if strings.Contains(expr, "|") || helpers.IsFunctionCall(expr) || helpers.IsComplexExpr(expr) {
pipe := parsePipeExpr(expr)
val, err = v.evalPipe(ctx, pipe)
if err != nil {
return fmt.Errorf("in expression '{{ %s }}': %w", expr, err)
}
ok = true
}
}
if !ok {
return nil
}
// Evaluate v-html expression to its string value and store in internal attribute
htmlStr := fmt.Sprint(val)
n.Attr = append(n.Attr, html.Attribute{Key: "data-v-html-content", Val: htmlStr})
// Clear children - v-html content will be output directly during rendering
n.FirstChild = nil
n.LastChild = nil
return nil
}