forked from codelingo/codelingo
/
docs.go
38 lines (30 loc) · 830 Bytes
/
docs.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
package commands
import (
"bytes"
"fmt"
"github.com/codegangsta/cli"
"github.com/microcosm-cc/bluemonday"
"github.com/pkg/browser"
"github.com/russross/blackfriday"
)
var DocsCMD = cli.Command{
Name: "docs",
Usage: "output documentation generated from tenets",
Action: docs,
}
func docs(c *cli.Context) {
fmt.Println("Opening tenet documentation in a new browser window ...")
var mdBuf bytes.Buffer
if err := writeTenetDoc(c, "", &mdBuf); err != nil {
oserrf("%v", err)
return
}
// Render markdown to HTML, and sanitise it to protect from
// malicious tenets.
htmlUnsafe := blackfriday.MarkdownBasic(mdBuf.Bytes())
html := bluemonday.UGCPolicy().SanitizeBytes(htmlUnsafe)
if err := browser.OpenReader(bytes.NewReader(html)); err != nil {
oserrf("opening docs in browser: %v", err)
return
}
}