From bc337e6ab5a75f1f1bfe3a83f3786d0afdb6346c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Nov 2018 11:01:27 +0100 Subject: Add inline shortcode support An inline shortcode's name must end with `.inline`, all lowercase. E.g.: ```bash {{< time.inline >}}{{ now }}{{< /time.inline >}} ``` The above will print the current date and time. Note that an inline shortcode's inner content is parsed and executed as a Go text template with the same context as a regular shortcode template. This means that the current page can be accessed via `.Page.Title` etc. This also means that there are no concept of "nested inline shortcodes". The same inline shortcode can be reused later in the same content file, with different params if needed, using the self-closing syntax: ``` {{< time.inline />}} ``` Fixes #4011 --- common/herrors/file_error.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'common/herrors') diff --git a/common/herrors/file_error.go b/common/herrors/file_error.go index 929cc800f..5af84adf5 100644 --- a/common/herrors/file_error.go +++ b/common/herrors/file_error.go @@ -92,7 +92,13 @@ func UnwrapFileError(err error) FileError { // with the given offset from the original. func ToFileErrorWithOffset(fe FileError, offset int) FileError { pos := fe.Position() - pos.LineNumber = pos.LineNumber + offset + return ToFileErrorWithLineNumber(fe, pos.LineNumber+offset) +} + +// ToFileErrorWithOffset will return a new FileError with the given line number. +func ToFileErrorWithLineNumber(fe FileError, lineNumber int) FileError { + pos := fe.Position() + pos.LineNumber = lineNumber return &fileError{cause: fe, fileType: fe.Type(), position: pos} } -- cgit v1.2.3