diff --git a/cfg/header_links.go b/cfg/header_links.go index d9151cc..c38835f 100644 --- a/cfg/header_links.go +++ b/cfg/header_links.go @@ -2,7 +2,7 @@ package cfg // See https://mycorrhiza.wiki/hypha/configuration/header import ( - "github.com/bouncepaw/mycomarkup/blocks" + "github.com/bouncepaw/mycomarkup/v2/blocks" "strings" ) diff --git a/go.mod b/go.mod index e2a3163..250741b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza go 1.16 require ( - github.com/bouncepaw/mycomarkup v1.0.3 + github.com/bouncepaw/mycomarkup/v2 v2.0.0 github.com/go-ini/ini v1.62.0 github.com/gorilla/feeds v1.1.1 github.com/gorilla/mux v1.8.0 @@ -17,4 +17,4 @@ require ( ) // Use this trick to test mycomarkup: -// replace github.com/bouncepaw/mycomarkup v1.0.3 => "/Users/bouncepaw/GolandProjects/mycomarkup" +replace github.com/bouncepaw/mycomarkup/v2 v2.0.0 => "/Users/bouncepaw/GolandProjects/mycomarkup" diff --git a/hyphae/backlinks.go b/hyphae/backlinks.go index d17a7ab..0923dc1 100644 --- a/hyphae/backlinks.go +++ b/hyphae/backlinks.go @@ -1,14 +1,14 @@ package hyphae import ( + "github.com/bouncepaw/mycomarkup/v2/tools" "os" "github.com/bouncepaw/mycorrhiza/util" - "github.com/bouncepaw/mycomarkup" - "github.com/bouncepaw/mycomarkup/blocks" - "github.com/bouncepaw/mycomarkup/links" - "github.com/bouncepaw/mycomarkup/mycocontext" + "github.com/bouncepaw/mycomarkup/v2" + "github.com/bouncepaw/mycomarkup/v2/links" + "github.com/bouncepaw/mycomarkup/v2/mycocontext" ) // Using set here seems like the most appropriate solution @@ -172,7 +172,7 @@ func extractHyphaLinks(h *Hypha) []string { // extractHyphaLinksFromContent extracts local hypha links from the provided text. func extractHyphaLinksFromContent(hyphaName string, contents string) []string { ctx, _ := mycocontext.ContextFromStringInput(hyphaName, contents) - linkVisitor, getLinks := LinkVisitor(ctx) + linkVisitor, getLinks := tools.LinkVisitor(ctx) // Ignore the result of BlockTree because we call it for linkVisitor. _ = mycomarkup.BlockTree(ctx, linkVisitor) foundLinks := getLinks() @@ -184,66 +184,3 @@ func extractHyphaLinksFromContent(hyphaName string, contents string) []string { } return result } - -// LinkVisitor creates a visitor which extracts all the links -// -// We consider inline link, rocket link, image gallery and transclusion targets to be links. -// TODO: replace with the one in Mycomarkup. -func LinkVisitor(ctx mycocontext.Context) ( - visitor func(block blocks.Block), - result func() []links.Link, -) { - var ( - collected []links.Link - extractBlock func(block blocks.Block) - ) - extractBlock = func(block blocks.Block) { - // fmt.Println(reflect.TypeOf(block)) - switch b := block.(type) { - case blocks.Paragraph: - // What a wonderful recursion technique you have! I like it. - extractBlock(b.Formatted) - case blocks.Heading: - extractBlock(b.GetContents()) - case blocks.List: - for _, item := range b.Items { - for _, sub := range item.Contents { - extractBlock(sub) - } - } - case blocks.Img: - for _, entry := range b.Entries { - extractBlock(entry) - } - case blocks.ImgEntry: - collected = append(collected, *b.Srclink) - case blocks.Transclusion: - link := *links.From(b.Target, "", ctx.HyphaName()) - collected = append(collected, link) - case blocks.LaunchPad: - for _, rocket := range b.Rockets { - extractBlock(rocket) - } - case blocks.Formatted: - for _, line := range b.Lines { - for _, span := range line { - switch s := span.(type) { - case blocks.InlineLink: - collected = append(collected, *s.Link) - } - } - } - case blocks.RocketLink: - if !b.IsEmpty { - collected = append(collected, b.Link) - } - } - } - visitor = func(block blocks.Block) { - extractBlock(block) - } - result = func() []links.Link { - return collected - } - return -} diff --git a/shroom/init.go b/shroom/init.go index 003f8f5..b681a67 100644 --- a/shroom/init.go +++ b/shroom/init.go @@ -6,7 +6,7 @@ import ( "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/views" - "github.com/bouncepaw/mycomarkup/globals" + "github.com/bouncepaw/mycomarkup/v2/globals" ) func init() { diff --git a/util/util.go b/util/util.go index 24f9680..8e39b12 100644 --- a/util/util.go +++ b/util/util.go @@ -9,7 +9,7 @@ import ( "regexp" "strings" - "github.com/bouncepaw/mycomarkup/util" + "github.com/bouncepaw/mycomarkup/v2/util" "github.com/bouncepaw/mycorrhiza/cfg" ) diff --git a/web/mutators.go b/web/mutators.go index 697aa3a..097031a 100644 --- a/web/mutators.go +++ b/web/mutators.go @@ -5,8 +5,8 @@ import ( "log" "net/http" - "github.com/bouncepaw/mycomarkup" - "github.com/bouncepaw/mycomarkup/mycocontext" + "github.com/bouncepaw/mycomarkup/v2" + "github.com/bouncepaw/mycomarkup/v2/mycocontext" "github.com/gorilla/mux" diff --git a/web/readers.go b/web/readers.go index 10b610e..8c0289d 100644 --- a/web/readers.go +++ b/web/readers.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/mux" + "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/mimetype" @@ -17,9 +18,9 @@ import ( "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/views" - "github.com/bouncepaw/mycomarkup" - "github.com/bouncepaw/mycomarkup/mycocontext" - "github.com/bouncepaw/mycorrhiza/cfg" + "github.com/bouncepaw/mycomarkup/v2" + "github.com/bouncepaw/mycomarkup/v2/mycocontext" + "github.com/bouncepaw/mycomarkup/v2/tools" ) func initReaders(r *mux.Router) { @@ -136,7 +137,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) { if errT == nil { ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT)) ctx = mycocontext.WithWebSiteURL(ctx, cfg.URL) - getOpenGraph, descVisitor, imgVisitor := mycomarkup.OpenGraphVisitors(ctx) + getOpenGraph, descVisitor, imgVisitor := tools.OpenGraphVisitors(ctx) ast := mycomarkup.BlockTree(ctx, descVisitor, imgVisitor) contents = mycomarkup.BlocksToHTML(ctx, ast) openGraph = getOpenGraph() diff --git a/web/stuff.go b/web/stuff.go index 3e53068..5d1d87b 100644 --- a/web/stuff.go +++ b/web/stuff.go @@ -19,8 +19,8 @@ import ( "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/views" - "github.com/bouncepaw/mycomarkup" - "github.com/bouncepaw/mycomarkup/mycocontext" + "github.com/bouncepaw/mycomarkup/v2" + "github.com/bouncepaw/mycomarkup/v2/mycocontext" ) func initStuff(r *mux.Router) {