Revert to old caption check, but add allowance for blank caption

This partly reverts a change made in response to #897, so that it still passes the test for a blank caption but also restores the ability for the developer to dynamically disable the caption entirely, e.g. with `undefined`. Also see #997.