1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-07 10:20:26 +00:00
mycorrhiza/shroom/mycomarkup_options.go
Timur Ismagilov 787882cb80 Mycomarkup: Update to v4.3.2
All things interwiki

Backlinks from img and rockets are temporarily broken until all other blocks gain support of interwiki.
2022-06-05 15:35:40 +03:00

55 lines
1.6 KiB
Go

package shroom
import (
"errors"
"github.com/bouncepaw/mycomarkup/v4/options"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
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 = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
binaryBlock = views.MediaRaw(h)
}
return
},
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()
}