mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Mycomarkup: Migrate to v4
This commit is contained in:
parent
2dcb1a5fe7
commit
17e006322f
@ -1,10 +1,11 @@
|
||||
package backlinks
|
||||
|
||||
import (
|
||||
"github.com/bouncepaw/mycomarkup/v3"
|
||||
"github.com/bouncepaw/mycomarkup/v3/links"
|
||||
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v3/tools"
|
||||
"github.com/bouncepaw/mycomarkup/v4"
|
||||
"github.com/bouncepaw/mycomarkup/v4/links"
|
||||
"github.com/bouncepaw/mycomarkup/v4/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v4/options"
|
||||
"github.com/bouncepaw/mycomarkup/v4/tools"
|
||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||
)
|
||||
|
||||
@ -34,7 +35,7 @@ func extractHyphaLinks(h hyphae.Hypha) []string {
|
||||
|
||||
// extractHyphaLinksFromContent extracts local hypha links from the provided text.
|
||||
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)
|
||||
// Ignore the result of BlockTree because we call it for linkVisitor.
|
||||
_ = mycomarkup.BlockTree(ctx, linkVisitor)
|
||||
|
@ -1,10 +1,10 @@
|
||||
package cfg
|
||||
|
||||
// See https://mycorrhiza.wiki/hypha/configuration/header
|
||||
import (
|
||||
"github.com/bouncepaw/mycomarkup/v3"
|
||||
"github.com/bouncepaw/mycomarkup/v3/blocks"
|
||||
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v4"
|
||||
"github.com/bouncepaw/mycomarkup/v4/blocks"
|
||||
"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.
|
||||
@ -24,7 +24,7 @@ func SetDefaultHeaderLinks() {
|
||||
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
|
||||
func ParseHeaderLinks(text string) {
|
||||
HeaderLinks = []HeaderLink{}
|
||||
ctx, _ := mycocontext.ContextFromStringInput("", text)
|
||||
ctx, _ := mycocontext.ContextFromStringInput(text, options.Options{}.FillTheRest())
|
||||
// We call for side-effects
|
||||
_ = mycomarkup.BlockTree(ctx, func(block blocks.Block) {
|
||||
switch launchpad := block.(type) {
|
||||
|
4
go.mod
4
go.mod
@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza
|
||||
go 1.18
|
||||
|
||||
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/gorilla/feeds v1.1.1
|
||||
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,
|
||||
// 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:
|
||||
// https://github.com/marwan-at-work/mod
|
||||
|
6
go.sum
6
go.sum
@ -1,7 +1,9 @@
|
||||
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/bouncepaw/mycomarkup/v3 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 h1:5zqb12aOw19xg8/0QIvgoA8oEW2doSdWqCbXltPEaPQ=
|
||||
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=
|
||||
|
@ -4,7 +4,7 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/bouncepaw/mycomarkup/v3/tools"
|
||||
"github.com/bouncepaw/mycomarkup/v4/tools"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
46
shroom/mycomarkup_options.go
Normal file
46
shroom/mycomarkup_options.go
Normal 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()
|
||||
}
|
@ -2,41 +2,3 @@
|
||||
//
|
||||
// Some of them are wrappers around functions provided by package hyphae. They manage history for you.
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycomarkup/v3/util"
|
||||
"github.com/bouncepaw/mycomarkup/v4/util"
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
)
|
||||
|
||||
|
@ -2,6 +2,8 @@ package web
|
||||
|
||||
// stuff.go is used for meta stuff about the wiki or all hyphae at once.
|
||||
import (
|
||||
"github.com/bouncepaw/mycomarkup/v4"
|
||||
"github.com/bouncepaw/mycorrhiza/shroom"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -13,8 +15,7 @@ import (
|
||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||
"github.com/bouncepaw/mycorrhiza/views"
|
||||
|
||||
"github.com/bouncepaw/mycomarkup/v3"
|
||||
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v4/mycocontext"
|
||||
)
|
||||
|
||||
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.
|
||||
ctx, _ := mycocontext.ContextFromStringInput(articlePath, string(content))
|
||||
ctx, _ := mycocontext.ContextFromStringInput(string(content), shroom.MarkupOptions(articlePath))
|
||||
ast := mycomarkup.BlockTree(ctx)
|
||||
result := mycomarkup.BlocksToHTML(ctx, ast)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -2,12 +2,12 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycomarkup/v4"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/bouncepaw/mycomarkup/v3"
|
||||
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v4/mycocontext"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@ -208,7 +208,7 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
||||
}
|
||||
|
||||
if action == "Preview" {
|
||||
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, textData)
|
||||
ctx, _ := mycocontext.ContextFromStringInput(textData, shroom.MarkupOptions(hyphaName))
|
||||
|
||||
util.HTTP200Page(
|
||||
w,
|
||||
|
@ -3,6 +3,8 @@ package web
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycomarkup/v4"
|
||||
"github.com/bouncepaw/mycorrhiza/shroom"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"io"
|
||||
"log"
|
||||
@ -13,7 +15,6 @@ import (
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/history"
|
||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||
@ -22,9 +23,8 @@ import (
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"github.com/bouncepaw/mycorrhiza/views"
|
||||
|
||||
"github.com/bouncepaw/mycomarkup/v3"
|
||||
"github.com/bouncepaw/mycomarkup/v3/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v3/tools"
|
||||
"github.com/bouncepaw/mycomarkup/v4/mycocontext"
|
||||
"github.com/bouncepaw/mycomarkup/v4/tools"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
if err == nil {
|
||||
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, textContents)
|
||||
ctx, _ := mycocontext.ContextFromStringInput(textContents, shroom.MarkupOptions(hyphaName))
|
||||
contents = mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))
|
||||
}
|
||||
}
|
||||
@ -213,8 +213,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
|
||||
case hyphae.ExistingHypha:
|
||||
fileContentsT, errT := os.ReadFile(h.TextFilePath())
|
||||
if errT == nil {
|
||||
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT))
|
||||
ctx = mycocontext.WithWebSiteURL(ctx, cfg.URL)
|
||||
ctx, _ := mycocontext.ContextFromStringInput(string(fileContentsT), shroom.MarkupOptions(hyphaName))
|
||||
getOpenGraph, descVisitor, imgVisitor := tools.OpenGraphVisitors(ctx)
|
||||
ast := mycomarkup.BlockTree(ctx, descVisitor, imgVisitor)
|
||||
contents = mycomarkup.BlocksToHTML(ctx, ast)
|
||||
|
Loading…
Reference in New Issue
Block a user