diff --git a/README.md b/README.md index 71fb70a..357fe84 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,28 @@ to the template relative to current working dir, e.g.: ``` +Optionally the delimiters can be defined: + +```markdown + +``` + +Or they can be switched off to disable processing: + +```markdown + +``` + +**Note:** Switching delimiters off really simply changes +them to ASCII characters "\x00" and "\x01" which, usually +should not occure in a template. + Templates can accept configuration data in YAML format which immediately -follows the `Include` tag: +follows the `Include` and `Delims` tag, if present: ```markdown var reIncludeDirective = regexp.MustCompile( - `(?s)`) + `(?s)` + + ``, +) func LoadTemplate( base string, path string, + left string, + right string, templates *template.Template, ) (*template.Template, error) { var ( @@ -52,7 +59,7 @@ func LoadTemplate( []byte("\n"), ) - templates, err = templates.New(name).Parse(string(body)) + templates, err = templates.New(name).Delims(left, right).Parse(string(body)) if err != nil { err = facts.Format( err, @@ -104,12 +111,15 @@ func ProcessIncludes( groups := reIncludeDirective.FindSubmatch(spec) var ( - path, config = string(groups[1]), groups[2] - data = map[string]interface{}{} + path, none, left, right, config = string(groups[1]), string(groups[2]), string(groups[3]), string(groups[4]), groups[5] + data = map[string]interface{}{} facts = karma.Describe("path", path) ) - + if none == "none" { + left = "\x00" + right = "\x01" + } err = yaml.Unmarshal(config, &data) if err != nil { err = facts. @@ -124,7 +134,7 @@ func ProcessIncludes( log.Tracef(vardump(facts, data), "including template %q", path) - templates, err = LoadTemplate(base, path, templates) + templates, err = LoadTemplate(base, path, left, right, templates) if err != nil { err = facts.Format(err, "unable to load template") diff --git a/pkg/mark/macro/macro.go b/pkg/mark/macro/macro.go index 5ed2389..a081beb 100644 --- a/pkg/mark/macro/macro.go +++ b/pkg/mark/macro/macro.go @@ -155,7 +155,7 @@ func ExtractMacros( return nil } } else { - macro.Template, err = includes.LoadTemplate(base, template, templates) + macro.Template, err = includes.LoadTemplate(base, template, "{{", "}}", templates) if err != nil { err = karma.Format(err, "unable to load template")