Documentation ¶
Overview ¶
Package template provides templating functionality.
Usage
import ( "fmt" gotemplate "text/template" "github.com/pulberg/terraform-docs/print" "github.com/pulberg/terraform-docs/template" "github.com/pulberg/terraform-docs/terraform" ) const mainTpl =` {{- if .Config.Sections.Header -}} {{- with .Module.Header -}} {{ colorize "\033[90m" . }} {{ end -}} {{- printf "\n\n" -}} {{ end -}}` func render(config *print.Config, module *terraform.Module) (string, error) { tt := template.New(config, &template.Item{ Name: "main", Text: mainTpl, TrimSpace: true, }) tt := template.New(config, items...) tt.CustomFunc(gotemplate.FuncMap{ "colorize": func(color string, s string) string { reset := "\033[0m" if !config.Settings.Color { color = "" reset = "" } return fmt.Sprintf("%s%s%s", color, s, reset) }, }) return tt.Render("main", module) }
Index ¶
- func ConvertMultiLineText(s string, isTable bool, isHeader bool, showHTML bool) string
- func ConvertOneLineCodeBlock(s string) string
- func CreateAnchorAsciidoc(prefix string, value string, anchor bool, escape bool) string
- func CreateAnchorMarkdown(prefix string, value string, anchor bool, escape bool) string
- func EscapeCharacters(s string, escape bool, escapePipe bool) string
- func GenerateIndentation(base int, extra int, char string) string
- func NormalizeURLs(s string, escape bool) string
- func SanitizeAsciidocTable(s string, escape bool, html bool) string
- func SanitizeDocument(s string, escape bool, html bool) string
- func SanitizeMarkdownTable(s string, escape bool, html bool) string
- func SanitizeName(name string, escape bool) string
- func SanitizeSection(s string, escape bool, html bool) string
- type Item
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMultiLineText ¶
ConvertMultiLineText converts a multi-line text into a suitable Markdown representation.
func ConvertOneLineCodeBlock ¶
ConvertOneLineCodeBlock converts a multi-line code block into a one-liner. Line breaks are replaced with single space.
func CreateAnchorAsciidoc ¶
CreateAnchorAsciidoc creates HTML anchor for AsciiDoc format.
func CreateAnchorMarkdown ¶
CreateAnchorMarkdown creates HTML anchor for Markdown format.
func EscapeCharacters ¶
EscapeCharacters escapes characters which have special meaning in Markdown into their corresponding literal.
func GenerateIndentation ¶
GenerateIndentation generates indentation of Markdown and AsciiDoc headers with base level of provided 'settings.IndentLevel' plus any extra level needed for subsection (e.g. 'Required Inputs' which is a subsection of 'Inputs' section)
func NormalizeURLs ¶
NormalizeURLs runs after escape function and normalizes URL back to the original state. For example any underscore in the URL which got escaped by 'EscapeCharacters' will be reverted back.
func SanitizeAsciidocTable ¶
SanitizeAsciidocTable converts passed 'string' to suitable AsciiDoc representation for a table. (including line-break, illegal characters, code blocks etc).
func SanitizeDocument ¶
SanitizeDocument converts passed 'string' to suitable Markdown or AsciiDoc representation for a document. (including line-break, illegal characters, code blocks etc).
func SanitizeMarkdownTable ¶
SanitizeMarkdownTable converts passed 'string' to suitable Markdown representation for a table. (including line-break, illegal characters, code blocks etc).
func SanitizeName ¶
SanitizeName escapes underscore character which have special meaning in Markdown.
func SanitizeSection ¶
SanitizeSection converts passed 'string' to suitable Markdown or AsciiDoc representation for a document. (including line-break, illegal characters, code blocks etc). This is in particular being used for header and footer.
IMPORTANT: SanitizeSection will never change the line-endings and preserve them as they are provided by the users.
Types ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a new Template with given name and content to be rendered with provided settings with use of built-in and custom functions.
func (*Template) CustomFunc ¶
func (t *Template) CustomFunc(funcs gotemplate.FuncMap)
CustomFunc adds new custom functions to the template if functions with the same names didn't exist.
func (Template) Funcs ¶
func (t Template) Funcs() gotemplate.FuncMap
Funcs return available template out of the box and custom functions.