bugfixes more search results and dump restore options
This commit is contained in:
parent
f4fcf0d9a8
commit
3cd460318a
124 changed files with 3915 additions and 9579 deletions
|
|
@ -20,12 +20,14 @@ func makeFilter() analysis.CharFilter {
|
|||
|
||||
func render(text string) Article {
|
||||
re := regexp.MustCompile("(<h[1-6])>(.+)(</h[1-6]>)")
|
||||
link := regexp.MustCompile(`id="(.+)">`)
|
||||
ws := regexp.MustCompile("\\s+")
|
||||
rend := blackfriday.MarkdownCommon([]byte(text))
|
||||
html := string(rend)
|
||||
index := buildIndex(html)
|
||||
html = strings.Replace(html, "<table>", `<table class="table">`, -1)
|
||||
html = re.ReplaceAllString(html, `${1} id="${2}">${2}${3}`)
|
||||
html = link.ReplaceAllStringFunc(html, makeLinkTitle)
|
||||
html = strings.Replace(html, "</h1>", `</h1><hr>`, -1)
|
||||
return Article{
|
||||
Search: ws.ReplaceAllString(string(filter.Filter(rend)), " "),
|
||||
|
|
@ -35,12 +37,17 @@ func render(text string) Article {
|
|||
}
|
||||
}
|
||||
|
||||
func makeLinkTitle(title string) string {
|
||||
return strings.Replace(title, " ", "+", -1)
|
||||
}
|
||||
|
||||
func buildIndex(html string) (ret string) {
|
||||
re := regexp.MustCompile("<h([1-6])>(.+)</h[1-6]>")
|
||||
hn := re.FindAllStringSubmatch(html, -1)
|
||||
for k, v := range hn {
|
||||
link := makeLinkTitle(v[2])
|
||||
ret += before(hn, k)
|
||||
ret += `<li><a href="#` + v[2] + `">` + v[2] + "</a>"
|
||||
ret += `<li><a href="#` + link + `">` + v[2] + "</a>"
|
||||
ret += after(hn, k)
|
||||
}
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue