If a closing shortcode is used, the .Inner variable will be populated with the content between the opening and closing shortcodes. If a closing shortcode is required, you can check the length of .Inner as an indicator of its existence.
I expected that if there’s no closing shortcode, .Inner would be an empty string, so checks for closing shortcodes wouldn’t have to use chomp, they could do {{ with .Inner }} directly.
Case 4: Erroneous usage (using .Inner without closing)
{{< foo >}} --> .Inner | len = 6 (\n+ \n+ 3 + \n)
Bar
Regarding #2, given that we don’t know if one or more leading or trailing newlines is intentional, I think we should leave this to shortcode authors as to whether or not to trim .Inner. However, documentation is misleading, implying that the length is zero:
you can check the length of .Inner as an indicator of its existence.
Regarding #4, it seems like we should fix this if possible, instead of relying on content authors to get it right. If the shortcode isn’t closed with either a closing tag or is self-closing, then .Inner should be nil.
I am having second thoughts about Case #2 due to comparison of behavior with code block render hooks. With code block render hooks, we trim all trailing newlines. With shortcodes, trailing new lines are not trimmed.