build: improve internal directive tool.
This commit is contained in:
parent
6f5604d59d
commit
05a489e021
2 changed files with 23 additions and 14 deletions
|
|
@ -61,11 +61,29 @@ func NewOption(file *paths.Path, match []string) *Option {
|
|||
}
|
||||
}
|
||||
|
||||
// Clean the selected directive from profile.
|
||||
// Clean removes selected directive line from input string.
|
||||
// Useful to remove directive text applied on some condition only
|
||||
func (o *Option) Clean(profile string) string {
|
||||
reg := regexp.MustCompile(`\s*` + Keyword + o.Name + ` .*$`)
|
||||
return strings.Replace(profile, o.Raw, reg.ReplaceAllString(o.Raw, ""), 1)
|
||||
func (o *Option) Clean(input string) string {
|
||||
return strings.Replace(input, o.Raw, o.cleanKeyword(o.Raw), 1)
|
||||
}
|
||||
|
||||
// cleanKeyword removes the dirextive keywork (#aa:...) from the input string
|
||||
func (o *Option) cleanKeyword(input string) string {
|
||||
reg := regexp.MustCompile(`\s*` + Keyword + o.Name + `( .*)?$`)
|
||||
return reg.ReplaceAllString(input, "")
|
||||
}
|
||||
|
||||
// Check if the directive is inline or if it is a paragraph
|
||||
func (o *Option) IsInline() bool {
|
||||
inline := true
|
||||
tmp := strings.Split(o.Raw, Keyword)
|
||||
if len(tmp) >= 1 {
|
||||
left := strings.TrimSpace(tmp[0])
|
||||
if len(left) == 0 {
|
||||
inline = false
|
||||
}
|
||||
}
|
||||
return inline
|
||||
}
|
||||
|
||||
func RegisterDirective(d Directive) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue