1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-05 02:29:54 +00:00

Migrate to Mycomarkup v2 uhhhhhhhh

Bloody hell mate. I'm losing my patience
This commit is contained in:
Timur Ismagilov 2021-09-12 11:58:03 +03:00
parent 84cb140cf8
commit 7347d3d7db
8 changed files with 19 additions and 81 deletions

View File

@ -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"
)

4
go.mod
View File

@ -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"

View File

@ -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
}

View File

@ -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() {

View File

@ -9,7 +9,7 @@ import (
"regexp"
"strings"
"github.com/bouncepaw/mycomarkup/util"
"github.com/bouncepaw/mycomarkup/v2/util"
"github.com/bouncepaw/mycorrhiza/cfg"
)

View File

@ -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"

View File

@ -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()

View File

@ -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) {