MCPcopy
hub / github.com/mudler/LocalAI / renderEngine

Function renderEngine

core/http/render.go:50–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func renderEngine() *TemplateRenderer {
51 // Parse all templates from embedded filesystem
52 tmpl := template.New("").Funcs(sprig.FuncMap())
53 tmpl = tmpl.Funcs(template.FuncMap{
54 "MDToHTML": markDowner,
55 })
56
57 // Recursively walk through embedded filesystem and parse all HTML templates
58 err := fs.WalkDir(viewsfs, "views", func(path string, d fs.DirEntry, err error) error {
59 if err != nil {
60 return err
61 }
62 if !d.IsDir() && strings.HasSuffix(path, ".html") {
63 data, err := viewsfs.ReadFile(path)
64 if err == nil {
65 // Remove .html extension to get template name (e.g., "views/index.html" -> "views/index")
66 templateName := strings.TrimSuffix(path, ".html")
67 _, err := tmpl.New(templateName).Parse(string(data))
68 if err != nil {
69 // If parsing fails, try parsing without explicit name (for templates with {{define}})
70 tmpl.Parse(string(data))
71 }
72 }
73 }
74 return nil
75 })
76 if err != nil {
77 // Log error but continue - templates might still work
78 fmt.Printf("Error walking views directory: %v\n", err)
79 }
80
81 return &TemplateRenderer{
82 templates: tmpl,
83 }
84}
85
86func markDowner(args ...any) template.HTML {
87 s := blackfriday.MarkdownCommon([]byte(fmt.Sprintf("%s", args...)))

Callers 2

APIFunction · 0.85
ExplorerFunction · 0.85

Calls 1

ParseMethod · 0.80

Tested by

no test coverage detected