2022-06-10 15:45:27 +00:00
|
|
|
package mycoopts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-08-21 20:52:10 +00:00
|
|
|
"git.sr.ht/~bouncepaw/mycomarkup/v5/options"
|
2022-06-10 15:45:27 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/interwiki"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MarkupOptions(hyphaName string) options.Options {
|
|
|
|
return options.Options{
|
|
|
|
HyphaName: hyphaName,
|
|
|
|
WebSiteURL: cfg.URL,
|
|
|
|
TransclusionSupported: true,
|
|
|
|
RedLinksSupported: true,
|
|
|
|
InterwikiSupported: true,
|
|
|
|
HyphaExists: func(hyphaName string) bool {
|
|
|
|
switch hyphae.ByName(hyphaName).(type) {
|
|
|
|
case *hyphae.EmptyHypha:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
IterateHyphaNamesWith: func(λ func(string)) {
|
|
|
|
for h := range hyphae.YieldExistingHyphae() {
|
|
|
|
λ(h.CanonicalName())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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 = hyphae.FetchMycomarkupFile(h)
|
|
|
|
case *hyphae.MediaHypha:
|
|
|
|
rawText, err = hyphae.FetchMycomarkupFile(h)
|
|
|
|
binaryBlock = mediaRaw(h)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
},
|
|
|
|
LocalTargetCanonicalName: util.CanonicalName,
|
|
|
|
LocalLinkHref: func(hyphaName string) string {
|
|
|
|
return "/hypha/" + util.CanonicalName(hyphaName)
|
|
|
|
},
|
|
|
|
LocalImgSrc: func(hyphaName string) string {
|
|
|
|
return "/binary/" + util.CanonicalName(hyphaName)
|
|
|
|
},
|
|
|
|
LinkHrefFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor,
|
|
|
|
ImgSrcFormatForInterwikiPrefix: interwiki.ImgSrcFormatFor,
|
|
|
|
}.FillTheRest()
|
|
|
|
}
|