diff --git a/README.md b/README.md index 4728a927..3f2fa694 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,8 @@ using the following data fields and functions: | Function | Example | Description | |-----------------|--------------------------------------------------|---------------------------------------------------------------------------------------------------| | `codefile` | `{{codefile "shell" "path/to/file.sh"}}` | Create a Markdown code block with the content of a file. Path is relative to the repository root. | +| `hasPrefix` | `{{if hasPrefix "FOO BAR" "FOO"}}` | Equivalent to [`strings.HasPrefix`](https://pkg.go.dev/strings#HasPrefix). | +| `hasSuffix` | `{{if hasSuffix "FOO BAR" "BAR"}}` | Equivalent to [`strings.HasSuffix`](https://pkg.go.dev/strings#HasSuffix). | | `lower` | `{{"EXAMPLE STRING" \| lower}}` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToLower). | | `plainmarkdown` | `{{"*example markdown*" \| plainmarkdown }}` | Render Markdown content as plaintext. | | `prefixlines` | `{{"example string" \| prefixlines "prefix: "}}` | Add a prefix to all (newline-separated) lines in a string. | @@ -489,4 +491,4 @@ cmp stdout expected-output.txt # compares stdout from binary with the golden fi cmp docs/index.md expected-index.md # compares the generated docs with the golden file in the text archive below cmp docs/data-sources/example.md expected-datasource.md # compares the generated docs with the golden file in the text archive below cmp docs/resources/example.md expected-resource.md # compares the generated docs with the golden file in the text archive below -``` \ No newline at end of file +``` diff --git a/internal/provider/template.go b/internal/provider/template.go index 43e785dc..1ddf205c 100644 --- a/internal/provider/template.go +++ b/internal/provider/template.go @@ -112,6 +112,8 @@ func newTemplate(providerDir, name, text string) (*template.Template, error) { tmpl.Funcs(map[string]interface{}{ "codefile": codeFile(providerDir), + "hasPrefix": strings.HasPrefix, + "hasSuffix": strings.HasSuffix, "lower": strings.ToLower, "plainmarkdown": mdplain.PlainMarkdown, "prefixlines": tmplfuncs.PrefixLines,