-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert_options.go
61 lines (50 loc) · 1.27 KB
/
convert_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
// SPDX-FileCopyrightText: 2021 Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package ciigo
import (
"fmt"
"regexp"
"strings"
)
const (
// DefaultRoot define default Root value for ConvertOptions.
DefaultRoot = `.`
)
// ConvertOptions define the options to use on Convert function.
type ConvertOptions struct {
// Root directory where its content will be embedded into Go source
// code.
// Default to DefaultRoot if its empty.
Root string
// Exclude define regular expresion to exclude certain paths from
// being scanned.
Exclude []string
// HTMLTemplate the HTML template to be used when converting markup
// file into HTML.
// If empty it will default to use embedded HTML template.
// See template_index_html.go for template format.
HTMLTemplate string
excRE []*regexp.Regexp
}
func (opts *ConvertOptions) init() (err error) {
var (
logp = `ConvertOptions.init`
)
if len(opts.Root) == 0 {
opts.Root = DefaultRoot
}
for _, str := range opts.Exclude {
str = strings.TrimSpace(str)
if len(str) == 0 {
continue
}
var re *regexp.Regexp
re, err = regexp.Compile(str)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
opts.excRE = append(opts.excRE, re)
defExcludes = append(defExcludes, str)
}
return nil
}