This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
91 lines (81 loc) · 2.31 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Package options provides a configuration data structure to pass when invoking the Mycomarkup parser.
package options
import (
"errors"
)
// Options is what you pass when invoking the parser.
type Options struct {
// Canonical hypha name that is being parsed now.
HyphaName string
// Canonical URL (including the protocol) of your website. Used for OpenGraph. Example: https://mycorrhiza.wiki.
WebSiteURL string
TransclusionSupported bool
RedLinksSupported bool
InterwikiSupported bool
HyphaExists func(string) bool
IterateHyphaNamesWith func(func(string))
HyphaHTMLData func(string) (rawText, binaryHtml string, err error)
LocalTargetCanonicalName func(string) string
LocalLinkHref func(string) string
LocalImgSrc func(string) string
LinkHrefFormatForInterwikiPrefix func(string) (string, InterwikiError)
ImgSrcFormatForInterwikiPrefix func(string) (string, InterwikiError)
}
func (opts Options) FillTheRest() Options {
if opts.HyphaExists == nil {
opts.HyphaExists = func(hyphaName string) bool {
return true
}
}
if opts.IterateHyphaNamesWith == nil {
opts.IterateHyphaNamesWith = func(func(string)) {}
}
if opts.HyphaHTMLData == nil {
opts.HyphaHTMLData = func(_ string) (string, string, error) {
return "", "", errors.New("HyphaHTMLData not set")
}
}
if opts.LocalLinkHref == nil {
opts.LocalLinkHref = func(hyphaName string) string {
return hyphaName
}
}
if opts.LocalImgSrc == nil {
opts.LocalImgSrc = func(hyphaName string) string {
return hyphaName
}
}
if opts.LocalTargetCanonicalName == nil {
opts.LocalTargetCanonicalName = func(target string) string {
return target
}
}
if opts.LinkHrefFormatForInterwikiPrefix == nil {
opts.LinkHrefFormatForInterwikiPrefix = func(prefix string) (string, InterwikiError) {
return "", NotSetUp
}
}
if opts.ImgSrcFormatForInterwikiPrefix == nil {
opts.ImgSrcFormatForInterwikiPrefix = func(prefix string) (string, InterwikiError) {
return "", NotSetUp
}
}
return opts
}
type InterwikiError int
func (i InterwikiError) Error() string {
switch i {
case Ok:
return "ok"
case UnknownPrefix:
return "unknown prefix"
case NotSetUp:
return "interwiki not set up"
}
return "naughty"
}
const (
Ok InterwikiError = iota
UnknownPrefix
NotSetUp
)