~emersion/drmdb

b980ecb715bb0e57c92beed31c619bed1f8aaa2a — Simon Ser 6 months ago 3075386
drmdoc: add support for headers with multiple property names
1 files changed, 13 insertions(+), 10 deletions(-)

M drmdoc/generate.go
M drmdoc/generate.go => drmdoc/generate.go +13 -10
@@ 69,10 69,7 @@ func parseProps(s string) map[string]string {
	var body strings.Builder
	for _, l := range lines {
		if l != "" && !strings.HasPrefix(l, indent) {
			bodyStr := strings.TrimSpace(body.String())
			if bodyStr != "" {
				m[header] = bodyStr
			}
			setProp(m, header, body.String())
			body.Reset()
			header = ""
		}


@@ 100,14 97,22 @@ func parseProps(s string) map[string]string {

		body.WriteString(strings.TrimPrefix(l, indent) + "\n")
	}
	bodyStr := strings.TrimSpace(body.String())
	if bodyStr != "" {
		m[header] = bodyStr
	}
	setProp(m, header, body.String())

	return m
}

func setProp(m map[string]string, header, body string) {
	body = strings.TrimSpace(body)
	if body == "" {
		return
	}

	for _, k := range strings.Split(header, ",") {
		m[strings.TrimSpace(k)] = body
	}
}

func titleToFilename(title string) string {
	fields := strings.Fields(title)
	return strings.ToLower(strings.Join(fields, "-"))


@@ 144,8 149,6 @@ func main() {
		log.Fatal(err)
	}

	// TODO: handle headings with multiple props in them such as
	// "privacy-screen sw-state, privacy-screen hw-state"
	props := parseProps(doc)

	symbol := titleToSymbol(outTitle)