-
Notifications
You must be signed in to change notification settings - Fork 24
/
html.go
59 lines (50 loc) · 1.57 KB
/
html.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package exporter
import (
"bytes"
"context"
"github.com/gomarkdown/markdown"
"github.com/jetstack/preflight/api"
"github.com/jetstack/preflight/pkg/packaging"
"github.com/jetstack/preflight/pkg/results"
)
// HTMLExporter is an Exporter that outputs a report in HTML format
type HTMLExporter struct {
}
// NewHTMLExporter creates a new HTMLExporter
func NewHTMLExporter() *HTMLExporter {
return &HTMLExporter{}
}
// Export writes the HTML report to a buffer
func (e *HTMLExporter) Export(ctx context.Context, policyManifest *packaging.PolicyManifest, intermediateJSON []byte, results *results.ResultCollection) (*bytes.Buffer, error) {
mdExporter := NewMarkdownExporter()
md, err := mdExporter.Export(ctx, policyManifest, intermediateJSON, results)
if err != nil {
return nil, err
}
htmlBytes := markdown.ToHTML(md.Bytes(), nil, nil)
writer := bytes.NewBuffer([]byte{})
_, err = writer.Write(htmlBytes)
if err != nil {
return nil, err
}
return writer, nil
}
// ExportIndex formats the supplied cluster summary
func (e *HTMLExporter) ExportIndex(ctx context.Context, clusterSummary *api.ClusterSummary) (*bytes.Buffer, error) {
mdExporter := NewMarkdownExporter()
md, err := mdExporter.ExportIndex(ctx, clusterSummary)
if err != nil {
return nil, err
}
htmlBytes := markdown.ToHTML(md.Bytes(), nil, nil)
writer := bytes.NewBuffer([]byte{})
_, err = writer.Write(htmlBytes)
if err != nil {
return nil, err
}
return writer, nil
}
// FileExtension returns the file extension for this exporter's format
func (e *HTMLExporter) FileExtension() string {
return ".html"
}