added dump/restore and fixed title stuff

This commit is contained in:
ston1th 2018-10-16 21:26:39 +02:00
commit 8d3187b160
13 changed files with 200627 additions and 189988 deletions

View file

@ -30,7 +30,7 @@ var (
func Render(p *core.Page) string {
rend := blackfriday.MarkdownCommon([]byte(p.Markdown))
index, html := buildIndex(string(rend))
index, html := buildTOC(string(rend))
html = strings.Replace(html, "<table>", `<table class="table">`, -1)
html = strings.Replace(html, "</h1>", `</h1><hr>`, -1)
html = strings.Replace(html, "<a", `<a target="_blank"`, -1)
@ -58,12 +58,17 @@ func UnstoreTitle(storeTitle string) (section, title string) {
return
}
func buildIndex(html string) (string, string) {
func buildTOC(html string) (string, string) {
var ret string
m := make(map[string]int)
hn := reIndex.FindAllStringSubmatch(html, -1)
html = reHeader.ReplaceAllString(html, `<a id="${2}" class="anchor"></a>${1}${2}${3}`)
html = reLink.ReplaceAllStringFunc(html, spaceReplace)
html = reLink.ReplaceAllStringFunc(html, func(s string) string {
if len(s) >= 3 {
return `id="` + Title(s[2:]) + `"`
}
return s
})
for k, v := range hn {
link := Title(v[2])
i := m[link]