helpers

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLinkHelper

func NewLinkHelper(formatter core.LinkFormatter, logger util.Logger) interface{}

NewLinkHelper creates a new template helper to generate an internal link using a LinkFormatter.

{{format-link "path/to/note.md" "An interesting subject"}} -> (depends on the LinkFormatter)

[[path/to/note]]
[An interesting subject](path/to/note)

func NewSlugHelper

func NewSlugHelper(lang string, logger util.Logger) interface{}

NewSlugHelper creates a new template helper to slugify text.

{{slug "This will be slugified!"}} -> this-will-be-slugified {{#slug}}This will be slugified!{{/slug}} -> this-will-be-slugified

func NewStyleHelper

func NewStyleHelper(styler core.Styler, logger util.Logger) interface{}

NewStyleHelper creates a new template helper which stylizes the text input according to predefined styling rules.

{{style "date" created}} {{#style "red"}}Hello, world{{/style}}

func RegisterConcat

func RegisterConcat()

RegisterConcat registers a {{concat}} template helper which concatenates two strings.

{{concat '> ' 'A quote'}} -> "> A quote"

func RegisterDate

func RegisterDate(logger util.Logger)

RegisterDate registers the {{date}} template helpers which format a given date.

It supports various styles: short, medium, long, full, year, time, timestamp, timestamp-unix or a custom strftime format.

{{date now}} -> 2009-11-17 {{date now "medium"}} -> Nov 17, 2009 {{date now "%Y-%m"}} -> 2009-11

func RegisterJSON added in v0.6.0

func RegisterJSON(logger util.Logger)

RegisterJSON registers a {{json}} template helper which serializes its parameter to a JSON value.

func RegisterJoin

func RegisterJoin()

RegisterJoin registers a {{join}} template helper which concatenates list items with the given separator.

{{join list ', '}} -> item1, item2, item3

func RegisterList

func RegisterList(supportsUTF8 bool)

RegisterList registers a {{list}} template helper which formats a slice of strings into a bulleted list.

func RegisterPrepend

func RegisterPrepend(logger util.Logger)

RegisterPrepend registers a {{prepend}} template helper which prepend a given string at the beginning of each line.

{{prepend '> ' 'A quote'}} -> "> A quote" {{#prepend '> '}}A quote{{/prepend}} -> "> A quote"

A quote on several lines {{/prepend}}

> A quote on > several lines

func RegisterShell

func RegisterShell(logger util.Logger)

RegisterShell registers the {{sh}} template helper, which runs shell commands.

{{#sh "tr '[a-z]' '[A-Z]'"}}Hello, world!{{/sh}} -> HELLO, WORLD! {{sh "echo 'Hello, world!'"}} -> Hello, world!

func RegisterSubstring added in v0.7.0

func RegisterSubstring()

RegisterSubstring registers a {{substring}} template helper which extracts a substring given a starting index and a length.

{{substring 'A full quote' 2 4}} -> "full" {{substring 'A full quote' -5 5}} -> "quote"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL