diff --git a/go.mod b/go.mod index bfbc6cb..8d8a253 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,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/v4 v4.3.0 => "/Users/bouncepaw/GolandProjects/mycomarkup" + replace github.com/bouncepaw/mycomarkup/v4 v4.3.0 => "/Users/bouncepaw/GolandProjects/mycomarkup" // Use this utility every time Mycomarkup gets a major update: // https://github.com/marwan-at-work/mod diff --git a/interwiki/interwiki.go b/interwiki/interwiki.go index da622a7..35c73a0 100644 --- a/interwiki/interwiki.go +++ b/interwiki/interwiki.go @@ -32,9 +32,16 @@ func Init() { func HrefLinkFormatFor(prefix string) string { if wiki, ok := theMap.byName[prefix]; ok { - return wiki.LinkFormat + return wiki.LinkHrefFormat } - return "{NAME}" + return "{NAME}" // TODO: error +} + +func ImgSrcFormatFor(prefix string) string { + if wiki, ok := theMap.byName[prefix]; ok { + return wiki.ImgSrcFormat + } + return "{NAME}" // TODO: error } func readInterwiki() ([]Wiki, error) { diff --git a/interwiki/wiki.go b/interwiki/wiki.go index a1595db..a2b33e0 100644 --- a/interwiki/wiki.go +++ b/interwiki/wiki.go @@ -48,12 +48,12 @@ type Wiki struct { // URL is the address of the wiki. URL string `json:"url"` - // LinkFormat is a format string for incoming interwiki links. The format strings should look like this: - // http://wiki.example.org/view/%s - // where %s is where text will be inserted. No other % instructions are supported yet. They will be added once we learn of their use cases. + // LinkHrefFormat is a format string for interwiki links. See Mycomarkup internal docs hidden deep inside for more information. // - // This field is optional. For other wikis, it is automatically set to /%s; for Mycorrhiza wikis, it is automatically set to /hypha/%s. - LinkFormat string `json:"link_format"` + // This field is optional. For other wikis, it is automatically set to /{NAME}; for Mycorrhiza wikis, it is automatically set to /hypha/{NAME}}. + LinkHrefFormat string `json:"link_href_format"` + + ImgSrcFormat string `json:"img_src_format"` // Description is a plain-text description of the wiki. Description string `json:"description"` @@ -95,12 +95,21 @@ func (w *Wiki) canonize() { w.Names[i] = util.CanonicalName(prefix) } - if w.LinkFormat == "" { + if w.LinkHrefFormat == "" { switch w.Engine { case Mycorrhiza: - w.LinkFormat = fmt.Sprintf("%s/hypha/%%s", w.URL) + w.LinkHrefFormat = fmt.Sprintf("%s/hypha/{NAME}", w.URL) default: - w.LinkFormat = fmt.Sprintf("%s/%%s", w.URL) + w.LinkHrefFormat = fmt.Sprintf("%s/{NAME}", w.URL) + } + } + + if w.ImgSrcFormat == "" { + switch w.Engine { + case Mycorrhiza: + w.ImgSrcFormat = fmt.Sprintf("%s/binary/{NAME}", w.URL) + default: + w.ImgSrcFormat = fmt.Sprintf("%s/{NAME}", w.URL) } } } diff --git a/shroom/mycomarkup_options.go b/shroom/mycomarkup_options.go index a5ed126..28ad906 100644 --- a/shroom/mycomarkup_options.go +++ b/shroom/mycomarkup_options.go @@ -48,6 +48,6 @@ func MarkupOptions(hyphaName string) options.Options { return "/binary/" + util.CanonicalName(hyphaName) }, LinkHrefFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor, - ImgSrcFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor, // TODO: dewrong + ImgSrcFormatForInterwikiPrefix: interwiki.ImgSrcFormatFor, }.FillTheRest() }