1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-08-08 23:03:47 +00:00

Mycomarkup: Migrate to v4

This commit is contained in:
Timur Ismagilov 2022-04-07 20:17:59 +03:00
parent 2dcb1a5fe7
commit 17e006322f
11 changed files with 78 additions and 67 deletions

View File

@ -1,10 +1,11 @@
package backlinks package backlinks
import ( import (
"github.com/bouncepaw/mycomarkup/v3" "github.com/bouncepaw/mycomarkup/v4"
"github.com/bouncepaw/mycomarkup/v3/links" "github.com/bouncepaw/mycomarkup/v4/links"
"github.com/bouncepaw/mycomarkup/v3/mycocontext" "github.com/bouncepaw/mycomarkup/v4/mycocontext"
"github.com/bouncepaw/mycomarkup/v3/tools" "github.com/bouncepaw/mycomarkup/v4/options"
"github.com/bouncepaw/mycomarkup/v4/tools"
"github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/hyphae"
) )
@ -34,7 +35,7 @@ func extractHyphaLinks(h hyphae.Hypha) []string {
// extractHyphaLinksFromContent extracts local hypha links from the provided text. // extractHyphaLinksFromContent extracts local hypha links from the provided text.
func extractHyphaLinksFromContent(hyphaName string, contents string) []string { func extractHyphaLinksFromContent(hyphaName string, contents string) []string {
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, contents) ctx, _ := mycocontext.ContextFromStringInput(contents, options.Options{HyphaName: hyphaName}.FillTheRest())
linkVisitor, getLinks := tools.LinkVisitor(ctx) linkVisitor, getLinks := tools.LinkVisitor(ctx)
// Ignore the result of BlockTree because we call it for linkVisitor. // Ignore the result of BlockTree because we call it for linkVisitor.
_ = mycomarkup.BlockTree(ctx, linkVisitor) _ = mycomarkup.BlockTree(ctx, linkVisitor)

View File

@ -1,10 +1,10 @@
package cfg package cfg
// See https://mycorrhiza.wiki/hypha/configuration/header
import ( import (
"github.com/bouncepaw/mycomarkup/v3" "github.com/bouncepaw/mycomarkup/v4"
"github.com/bouncepaw/mycomarkup/v3/blocks" "github.com/bouncepaw/mycomarkup/v4/blocks"
"github.com/bouncepaw/mycomarkup/v3/mycocontext" "github.com/bouncepaw/mycomarkup/v4/mycocontext"
"github.com/bouncepaw/mycomarkup/v4/options"
) )
// HeaderLinks is a list off current header links. Feel free to iterate it directly but do not modify it by yourself. Call ParseHeaderLinks if you need to set new header links. // HeaderLinks is a list off current header links. Feel free to iterate it directly but do not modify it by yourself. Call ParseHeaderLinks if you need to set new header links.
@ -24,7 +24,7 @@ func SetDefaultHeaderLinks() {
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links. // ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
func ParseHeaderLinks(text string) { func ParseHeaderLinks(text string) {
HeaderLinks = []HeaderLink{} HeaderLinks = []HeaderLink{}
ctx, _ := mycocontext.ContextFromStringInput("", text) ctx, _ := mycocontext.ContextFromStringInput(text, options.Options{}.FillTheRest())
// We call for side-effects // We call for side-effects
_ = mycomarkup.BlockTree(ctx, func(block blocks.Block) { _ = mycomarkup.BlockTree(ctx, func(block blocks.Block) {
switch launchpad := block.(type) { switch launchpad := block.(type) {

4
go.mod
View File

@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza
go 1.18 go 1.18
require ( require (
github.com/bouncepaw/mycomarkup/v3 v3.6.2 github.com/bouncepaw/mycomarkup/v4 v4.0.0
github.com/go-ini/ini v1.63.2 github.com/go-ini/ini v1.63.2
github.com/gorilla/feeds v1.1.1 github.com/gorilla/feeds v1.1.1
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
@ -22,7 +22,7 @@ require (
// Use this trick to test local Mycomarkup changes, replace the path with yours, // Use this trick to test local Mycomarkup changes, replace the path with yours,
// but do not commit the change to the path: // but do not commit the change to the path:
// replace github.com/bouncepaw/mycomarkup/v3 v3.6.2 => "/Users/bouncepaw/GolandProjects/mycomarkup" // replace github.com/bouncepaw/mycomarkup/v4 v4.0.0 => "/Users/bouncepaw/GolandProjects/mycomarkup"
// Use this utility every time Mycomarkup gets a major update: // Use this utility every time Mycomarkup gets a major update:
// https://github.com/marwan-at-work/mod // https://github.com/marwan-at-work/mod

6
go.sum
View File

@ -1,7 +1,9 @@
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bouncepaw/mycomarkup/v3 v3.6.2 h1:5zqb12aOw19xg8/0QIvgoA8oEW2doSdWqCbXltPEaPQ= github.com/bouncepaw/mycomarkup/v4 v3.6.2 h1:5zqb12aOw19xg8/0QIvgoA8oEW2doSdWqCbXltPEaPQ=
github.com/bouncepaw/mycomarkup/v3 v3.6.2/go.mod h1:BpiGUVsYCgRZCDxF0iIdc08LJokm/Ab36S/Hif0J6D0= github.com/bouncepaw/mycomarkup/v4 v3.6.2/go.mod h1:BpiGUVsYCgRZCDxF0iIdc08LJokm/Ab36S/Hif0J6D0=
github.com/bouncepaw/mycomarkup/v4 v4.0.0 h1:qokseZ+otcFuQ5vARdvxKqjlEZFMvsjFJ7YpJ4sUr8c=
github.com/bouncepaw/mycomarkup/v4 v4.0.0/go.mod h1:y0b8U6Xfnh3KfNUpG3QuAXRJwqFPPpmS2kYvLzaf688=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y= github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=

View File

@ -4,7 +4,7 @@
package migration package migration
import ( import (
"github.com/bouncepaw/mycomarkup/v3/tools" "github.com/bouncepaw/mycomarkup/v4/tools"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"

View File

@ -0,0 +1,46 @@
package shroom
import (
"errors"
"github.com/bouncepaw/mycomarkup/v4/options"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/views"
)
func MarkupOptions(hyphaName string) options.Options {
return fillMycomarkupOptions(options.Options{
HyphaName: hyphaName,
WebSiteURL: cfg.URL,
TransclusionSupported: true,
})
}
func fillMycomarkupOptions(opts options.Options) options.Options {
opts.HyphaExists = func(hyphaName string) bool {
switch hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
return false
default:
return true
}
}
opts.HyphaHTMLData = func(hyphaName string) (rawText, binaryBlock string, err error) {
switch h := hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
err = errors.New("Hypha " + hyphaName + " does not exist")
case *hyphae.TextualHypha:
rawText, err = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
binaryBlock = views.MediaRaw(h)
}
return
}
opts.IterateHyphaNamesWith = func(λ func(string)) {
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
}
}
return opts.FillTheRest()
}

View File

@ -2,41 +2,3 @@
// //
// Some of them are wrappers around functions provided by package hyphae. They manage history for you. // Some of them are wrappers around functions provided by package hyphae. They manage history for you.
package shroom package shroom
import (
"errors"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v3/globals"
)
func init() {
// TODO: clean this complete and utter mess
globals.HyphaExists = func(hyphaName string) bool {
switch hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
return false
default:
return true
}
}
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
switch h := hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
err = errors.New("Hypha " + hyphaName + " does not exist")
case *hyphae.TextualHypha:
rawText, err = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
binaryBlock = views.MediaRaw(h)
}
return
}
globals.HyphaIterate = func(λ func(string)) {
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
}
}
}

View File

@ -8,7 +8,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/bouncepaw/mycomarkup/v3/util" "github.com/bouncepaw/mycomarkup/v4/util"
"github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/cfg"
) )

View File

@ -2,6 +2,8 @@ package web
// stuff.go is used for meta stuff about the wiki or all hyphae at once. // stuff.go is used for meta stuff about the wiki or all hyphae at once.
import ( import (
"github.com/bouncepaw/mycomarkup/v4"
"github.com/bouncepaw/mycorrhiza/shroom"
"github.com/bouncepaw/mycorrhiza/viewutil" "github.com/bouncepaw/mycorrhiza/viewutil"
"io" "io"
"net/http" "net/http"
@ -13,8 +15,7 @@ import (
"github.com/bouncepaw/mycorrhiza/l18n" "github.com/bouncepaw/mycorrhiza/l18n"
"github.com/bouncepaw/mycorrhiza/views" "github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v3" "github.com/bouncepaw/mycomarkup/v4/mycocontext"
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
) )
func initHelp(r *mux.Router) { func initHelp(r *mux.Router) {
@ -64,7 +65,7 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
} }
// TODO: change for the function that uses byte array when there is such function in mycomarkup. // TODO: change for the function that uses byte array when there is such function in mycomarkup.
ctx, _ := mycocontext.ContextFromStringInput(articlePath, string(content)) ctx, _ := mycocontext.ContextFromStringInput(string(content), shroom.MarkupOptions(articlePath))
ast := mycomarkup.BlockTree(ctx) ast := mycomarkup.BlockTree(ctx)
result := mycomarkup.BlocksToHTML(ctx, ast) result := mycomarkup.BlocksToHTML(ctx, ast)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -2,12 +2,12 @@ package web
import ( import (
"fmt" "fmt"
"github.com/bouncepaw/mycomarkup/v4"
"github.com/bouncepaw/mycorrhiza/viewutil" "github.com/bouncepaw/mycorrhiza/viewutil"
"log" "log"
"net/http" "net/http"
"github.com/bouncepaw/mycomarkup/v3" "github.com/bouncepaw/mycomarkup/v4/mycocontext"
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -208,7 +208,7 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
} }
if action == "Preview" { if action == "Preview" {
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, textData) ctx, _ := mycocontext.ContextFromStringInput(textData, shroom.MarkupOptions(hyphaName))
util.HTTP200Page( util.HTTP200Page(
w, w,

View File

@ -3,6 +3,8 @@ package web
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/bouncepaw/mycomarkup/v4"
"github.com/bouncepaw/mycorrhiza/shroom"
"github.com/bouncepaw/mycorrhiza/viewutil" "github.com/bouncepaw/mycorrhiza/viewutil"
"io" "io"
"log" "log"
@ -13,7 +15,6 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/l18n" "github.com/bouncepaw/mycorrhiza/l18n"
@ -22,9 +23,8 @@ import (
"github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views" "github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v3" "github.com/bouncepaw/mycomarkup/v4/mycocontext"
"github.com/bouncepaw/mycomarkup/v3/mycocontext" "github.com/bouncepaw/mycomarkup/v4/tools"
"github.com/bouncepaw/mycomarkup/v3/tools"
) )
func initReaders(r *mux.Router) { func initReaders(r *mux.Router) {
@ -140,7 +140,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
var textContents, err = history.FileAtRevision(h.TextFilePath(), revHash) var textContents, err = history.FileAtRevision(h.TextFilePath(), revHash)
if err == nil { if err == nil {
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, textContents) ctx, _ := mycocontext.ContextFromStringInput(textContents, shroom.MarkupOptions(hyphaName))
contents = mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx)) contents = mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))
} }
} }
@ -213,8 +213,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
case hyphae.ExistingHypha: case hyphae.ExistingHypha:
fileContentsT, errT := os.ReadFile(h.TextFilePath()) fileContentsT, errT := os.ReadFile(h.TextFilePath())
if errT == nil { if errT == nil {
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT)) ctx, _ := mycocontext.ContextFromStringInput(string(fileContentsT), shroom.MarkupOptions(hyphaName))
ctx = mycocontext.WithWebSiteURL(ctx, cfg.URL)
getOpenGraph, descVisitor, imgVisitor := tools.OpenGraphVisitors(ctx) getOpenGraph, descVisitor, imgVisitor := tools.OpenGraphVisitors(ctx)
ast := mycomarkup.BlockTree(ctx, descVisitor, imgVisitor) ast := mycomarkup.BlockTree(ctx, descVisitor, imgVisitor)
contents = mycomarkup.BlocksToHTML(ctx, ast) contents = mycomarkup.BlocksToHTML(ctx, ast)