diff --git a/README.md b/README.md index 216841d..1ea90af 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,34 @@ for example: Ticket: ${0} --> ``` +Macros can also use inline templates. +Inline templates are templates where the template content +is described in the ``. +The `Template` value starts with a `#`, followed by the key +used in the ``. +The key's value must be a string which defines the template's content. + +```markdown + + + + and some + content + +``` + + ### Code Blocks If you have long code blocks, you can make them collapsible with the [Code Block Macro]: diff --git a/pkg/mark/macro/macro.go b/pkg/mark/macro/macro.go index 48e37c3..5ed2389 100644 --- a/pkg/mark/macro/macro.go +++ b/pkg/mark/macro/macro.go @@ -134,13 +134,36 @@ func ExtractMacros( macro Macro ) - macro.Template, err = includes.LoadTemplate(base, template, templates) - if err != nil { - err = karma.Format(err, "unable to load template") + if strings.HasPrefix(template, "#") { + cfg := map[string]interface{}{} - return nil + err = yaml.Unmarshal([]byte(config), &cfg) + if err != nil { + err = karma.Format( + err, + "unable to unmarshal macros config template", + ) + return nil + } + body, _ := cfg[template[1:]].(string) + macro.Template, err = templates.New(template).Parse(body) + if err != nil { + err = karma.Format( + err, + "unable to parse template", + ) + return nil + } + } else { + macro.Template, err = includes.LoadTemplate(base, template, templates) + if err != nil { + err = karma.Format(err, "unable to load template") + + return nil + } } + facts := karma. Describe("template", template). Describe("expr", expr)