-
Notifications
You must be signed in to change notification settings - Fork 0
/
markup.go
39 lines (34 loc) · 1.01 KB
/
markup.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
package main
import (
"bytes"
"fmt"
"github.com/krrrr38/blackfriday"
"github.com/swdyh/go-enumerable/src/enumerable"
"regexp"
"sync"
)
// MakeSlide generate html from markdown text
func MakeSlide(pageTotal *int, markdown []byte) []byte {
var buffer bytes.Buffer
rawPages := regexp.MustCompile("(?m)^!SLIDE").Split(string(markdown[:]), -1)
// remove empty page
var nonContentFilter func([]string) []string
enumerable.MakeFilter(&nonContentFilter, func(page string) bool { return page != "" })
pages := nonContentFilter(rawPages)
htmls := make([]string, len(pages))
var wg sync.WaitGroup
for i, page := range pages {
wg.Add(1)
go func(i int, page string) {
content := blackfriday.MarkdownCommon([]byte(page))
htmls[i] = fmt.Sprintf("<div class=\"content\" id=\"slide-%d\"><div class=\"container\">%s</div></div>", i+(*pageTotal), string(content[:]))
wg.Done()
}(i, page)
}
wg.Wait()
(*pageTotal) += len(pages)
for _, html := range htmls {
buffer.WriteString(html)
}
return buffer.Bytes()
}