Text Styling
The templating engine provides a set of functions to apply style to a text:
| Function | Effect | Example |
|---|---|---|
bold | Bold | {{bold .Text}} |
italic | Italic | {{italic .Text}} |
underline | Underline | {{underline .Text}} |
strike | Strikethrough | {{strike .Text}} |
fontSize | Font size in points | {{fontSize .Text 14}} |
color | Text color | {{color .Text "FF0000"}} |
highlight | Word text highlight | {{highlight .Text "yellow"}} |
shadeTextBg | Background shading behind text | {{shadeTextBg .Text "EEEEEE"}} |
Color and shading functions accept a six-digit hexadecimal RGB value, with or without a leading #.
For example, "FF0000" or "#FF0000".
While highlight takes a Word highlight color name, such as yellow.
Combine styles
Use inlineStyledText to apply multiple styles to one value. Style order is flexible; use the tokens below:
{{inlineStyledText .Text "b" "i" "fs:14" "#FF0000" "bg:#C0FFEE"}}| Style | Accepted tokens |
|---|---|
| Bold | b, bold |
| Italic | i, italic |
| Underline | u, underline |
| Strikethrough | s, strike, strikethrough |
| Font size | fs:<size>, fontSize:<size> (for example, fs:14) |
| Text color | RRGGBB, #RRGGBB |
| Background shading | bg:RRGGBB, bg:#RRGGBB |
| Highlight | A Word highlight color name, such as yellow |
or you pass the styles as a list with styledText:
{{styledText .Text (list "b" "i" "fs:14")}}list is a built-in helper that constructs the slice of style values.
Dynamic styles
This also enables a go slice to be passed as argument. Example:
{{styledText .Text .Style}}
where .Style contains the style tokens.
{
"Text": "Hello World",
"Style": ["#F0F0F0", "bg:#FF0000", "b", "i", "u", "s", "fs:20"]
}Preserve line breaks
For values containing newline characters, choose how those newlines should appear in Word:
{{preserveNewline .Text}}turns newlines into line breaks within the same paragraph (Shift+Enter).{{breakParagraph .Text}}turns newlines into separate paragraphs (Enter).
For the complete function reference, see Built-in functions.