forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_examples.go
42 lines (36 loc) · 1.04 KB
/
parse_examples.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
package main
import (
"io/ioutil"
"regexp"
)
const (
newHeader = `<summary>Examples with this field (click to open)</summary>
<br>
<ul>`
newHeaderAlt = `<summary>Examples (click to open)</summary>
<br>
<ul>`
newLink = ` <li> <a href="$2">$1</a>`
newDetails = `</ul>
</details>`
)
var (
headerRegex = regexp.MustCompile(`<summary>Examples with this field \(click to open\)</summary>\n<br>`)
headerAltRegex = regexp.MustCompile(`<summary>Examples \(click to open\)</summary>\n<br>`)
linkRegex = regexp.MustCompile(`- \[\x60(.+?)\x60\]\((.+?)\)`)
detailsRegex = regexp.MustCompile(`</details>`)
)
func parseExamples() {
file, err := ioutil.ReadFile("site/fields/index.html")
if err != nil {
panic(err)
}
file = headerRegex.ReplaceAll(file, []byte(newHeader))
file = headerAltRegex.ReplaceAll(file, []byte(newHeaderAlt))
file = linkRegex.ReplaceAll(file, []byte(newLink))
file = detailsRegex.ReplaceAll(file, []byte(newDetails))
err = ioutil.WriteFile("site/fields/index.html", file, 0644)
if err != nil {
panic(err)
}
}