diff --git a/server/main.go b/server/main.go
index c5c88d6..13c3dd1 100644
--- a/server/main.go
+++ b/server/main.go
@@ -3,6 +3,7 @@ package server
import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
+ "github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/parser"
"vultras.su/core/bond"
"vultras.su/core/bond/contents"
@@ -11,7 +12,7 @@ import (
"path"
"os"
"fmt"
- //"strings"
+ "strings"
"bytes"
)
@@ -32,6 +33,7 @@ type ServerOptions struct {
WikiExt string
WebPath string
AddFileNavigation bool
+ AddDocNavigation bool
}
type Server struct {
@@ -88,6 +90,113 @@ func (srv *Server) pageFooter() string {
return htmlFooter
}
+type Heading struct {
+ Id string
+ Level int
+ Text string
+}
+
+func getDocumentHeadings(doc ast.Node) []Heading {
+ ret := []Heading{}
+ ast.WalkFunc(doc, func(node ast.Node, entering bool) ast.WalkStatus {
+ heading, ok := node.(*ast.Heading)
+ if !ok {
+ return ast.GoToNext
+ }
+ children := node.GetChildren()
+ if len(children) > 0 && !entering {
+ leaf := children[0].AsLeaf()
+ if leaf == nil {
+ return ast.GoToNext
+ }
+ ret = append(ret, Heading{
+ Id: heading.HeadingID,
+ Level: heading.Level,
+ Text: string(leaf.Literal),
+ })
+ return ast.SkipChildren
+ }
+
+ return ast.GoToNext
+ })
+ return ret
+}
+
+type HeadingTree struct {
+ Heading Heading
+ Children HeadingTrees
+}
+
+type HeadingTrees []*HeadingTree
+
+func makeHeadingTrees(hs []Heading) HeadingTrees {
+ fmt.Println("fooooooooooooooouuuuuuuuund", len(hs), hs)
+ if len(hs) == 0 {
+ return nil
+ }
+
+ if len(hs) == 1 {
+ return HeadingTrees{
+ &HeadingTree{
+ Heading: hs[0],
+ },
+ }
+ }
+
+ var (
+ lasti int
+ found bool
+ )
+
+ first := hs[0]
+ rest := hs[1:]
+ for i, h := range rest {
+ if first.Level >= h.Level {
+ fmt.Println("thefound: ", first, h)
+ lasti = i+1
+ found = true
+ break
+ }
+ }
+
+ if !found {
+ fmt.Println("in not found")
+ return HeadingTrees{
+ &HeadingTree{
+ Heading: first,
+ Children: makeHeadingTrees(rest),
+ },
+ }
+ }
+
+ fmt.Println("through", lasti)
+ return append(
+ makeHeadingTrees(hs[:lasti]),
+ makeHeadingTrees(hs[lasti:])... ,
+ )
+}
+
+func RenderHeadingTrees(trees HeadingTrees, first bool) string {
+ var b strings.Builder
+ fmt.Fprint(&b, "")
+ return b.String()
+}
+
func (srv *Server) ProcessToHtml(urlPath, filePath string, bts []byte) ([]byte, error) {
var b bytes.Buffer
doc := srv.makeMdParser().Parse(bts)
@@ -133,14 +242,21 @@ func (srv *Server) ProcessToHtml(urlPath, filePath string, bts []byte) ([]byte,
fmt.Fprint(&b, "")
}
- fmt.Fprint(&b, "