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 --- parser/pageparser/item.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'parser/pageparser/item.go') diff --git a/parser/pageparser/item.go b/parser/pageparser/item.go index 0567bd8b9..644c20e87 100644 --- a/parser/pageparser/item.go +++ b/parser/pageparser/item.go @@ -42,6 +42,10 @@ func (i Item) IsShortcodeName() bool { return i.Type == tScName } +func (i Item) IsInlineShortcodeName() bool { + return i.Type == tScNameInline +} + func (i Item) IsLeftShortcodeDelim() bool { return i.Type == tLeftDelimScWithMarkup || i.Type == tLeftDelimScNoMarkup } @@ -119,6 +123,7 @@ const ( tRightDelimScWithMarkup tScClose tScName + tScNameInline tScParam tScParamVal -- cgit v1.2.3