Repository: gohugoio/hugo (language: go)

Issue:
hugo panic when running hugo --buildDrafts on v0.100.0+ when using markdownify in templates
### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.101.0-DEV-4daac654d90bdc6adf92bf8b15a4aa45d7d62efd linux/amd64 BuildDate=2022-05-31T09:19:15Z
</pre>

### Does this issue reproduce with the latest release?

Yes.

### Issue

When running `hugo --buildDrafts` or `hugo serve --buildDrafts` on my site, I get a bunch of panic backtraces like this:

<details>
<summary>
Click to see the backtrace
</summary>

```
ERR: runtime error: invalid memory address or nil pointer dereference
stacktrace from panic:
goroutine 142 [running]:
runtime/debug.Stack()
        /home/kmodi/go/src/runtime/debug/stack.go:24 +0x65
github.com/gohugoio/hugo/common/herrors.Recover({0x0, 0x0, 0x0})
        /home/kmodi/downloads/git/hugo/common/herrors/errors.go:45 +0x9c
panic({0x1df9e40, 0x36491e0})
        /home/kmodi/go/src/runtime/panic.go:838 +0x207
github.com/gohugoio/hugo/hugolib.(*shortcodeHandler).transferNames(0x0, 0xc002708370)
        /home/kmodi/downloads/git/hugo/hugolib/shortcode.go:461 +0x4a
github.com/gohugoio/hugo/hugolib.(*pageContentOutput).RenderString(0xc0013f0700, {0xc003cab020, 0x1, 0x7f35c27b4d01?})
        /home/kmodi/downloads/git/hugo/hugolib/page__per_output.go:442 +0xa11
github.com/gohugoio/hugo/tpl/transform.(*Namespace).Markdownify(0xc000a7e0d0, {0x1d4f6e0?, 0xc003caaf70})
        /home/kmodi/downloads/git/hugo/tpl/transform/transform.go:127 +0xae
reflect.Value.call({0x1daa740?, 0xc000a7e170?, 0xc000631ea0?}, {0x203d311, 0x4}, {0xc00257b050, 0x1, 0x260d640?})
        /home/kmodi/go/src/reflect/value.go:556 +0x845
reflect.Value.Call({0x1daa740?, 0xc000a7e170?, 0x0?}, {0xc00257b050, 0x1, 0x1})
        /home/kmodi/go/src/reflect/value.go:339 +0xbf
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.safeCall({0x1daa740?, 0xc000a7e170?, 0xc003caaf70?}, {0xc00257b050?, 0x260d640?, 0x1db3380?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/funcs.go:368 +0x9d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCall(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x1245509?}, {0x1daa740?, 0xc000a7e170?, 0xc?}, 0x0, {0x2604098, 0xc0005bda10}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:386 +0xb0a
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalFunction(0xc005d4e8a8, {0x202fe60?, 0xc000df40f0?, 0x1?}, 0x1?, {0x2604098, 0xc0005bda10}, {0xc0002488b0, 0x1, 0x1}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:180 +0x46e
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCommand(0xc005d4e8a8, {0x202fe60?, 0xc000df40f0?, 0x0?}, 0xc005d4e8a8?, {0x1d4f6e0?, 0xc003caaf70?, 0xc00257af78?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:488 +0xea
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalPipeline(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x0?}, 0xc0005b5a40)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:457 +0x145
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x1e156e0?}, {0x2603f30?, 0xc00078ad50})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:261 +0x225
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x1d31920?}, {0x2604290?, 0xc0005bd950?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkIfOrWith(0xc005d4e8a8, 0xa, {0x202fe60?, 0xc000df40f0?, 0xc0005b5800?}, 0x2?, 0x2?, 0xc0005bd950)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:307 +0x17c
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc005d4e8a8, {0x202fe60?, 0xc000df40f0?, 0x1e156e0?}, {0x2604248?, 0xc000787280?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:271 +0x1d6
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x1d31920?}, {0x2604290?, 0xc0005bd350?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkIfOrWith(0xc005d4e8a8, 0xa, {0x202fe60?, 0xc000df40f0?, 0xc0005b5560?}, 0x18?, 0x99?, 0xc00078ad80)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:304 +0x14a
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc005d4e8a8, {0x202fe60?, 0xc000df40f0?, 0x1e156e0?}, {0x2604248?, 0xc000787300?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:271 +0x1d6
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0x1d4f6e0?}, {0x2604290?, 0xc0005bd170?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkIfOrWith(0xc005d4e8a8, 0x13, {0x202fe60?, 0xc000df40f0?, 0xc0005b5440?}, 0xdb6db6db6db6d?, 0xc0025731d0?, 0xc0005bd170)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:307 +0x17c
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc005d4e8a8, {0x202fe60?, 0xc000df40f0?, 0x3?}, {0x2604518?, 0xc000787340?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:285 +0x154
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a88a8, {0x202fe60?, 0xc000df40f0?, 0xc00257ade0?}, {0x2604290?, 0xc0005bce10?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*Template).executeWithState(0xc00255f890?, 0x1d4cda0?, {0x202fe60?, 0xc000df40f0?, 0x50001?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:136 +0x135
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*executer).ExecuteWithContext(0xc000a7e310, {0x2601860, 0xc00255f890}, {0x7f359b5a8248, 0xc000c114a0}, {0x25f01c0, 0xc0022c0060}, {0x202fe60, 0xc000df40f0})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:101 +0x345
github.com/gohugoio/hugo/tpl/tplimpl.(*templateExec).ExecuteWithContext(0xc000809350, {0x2601860, 0xc00255f890}, {0x25fa9f0?, 0xc000c114a0}, {0x25f01c0, 0xc0022c0060}, {0x202fe60, 0xc000df40f0})
        /home/kmodi/downloads/git/hugo/tpl/tplimpl/template.go:258 +0x59e
github.com/gohugoio/hugo/tpl/partials.(*Namespace).include(0xc000a555b0, {0x2601860, 0xc00255f890}, {0xc000c3617b, 0x16}, {0xc003caae60?, 0x10?, 0x7f35c27b4d28?})
        /home/kmodi/downloads/git/hugo/tpl/partials/partials.go:166 +0x335
github.com/gohugoio/hugo/tpl/partials.(*Namespace).Include(0xc000a555b0, {0x2601860?, 0xc00255f890?}, {0xc000c3617b?, 0x1e54700?}, {0xc003caae60?, 0xc005d4ed48?, 0x4de6de?})
        /home/kmodi/downloads/git/hugo/tpl/partials/partials.go:106 +0x39
reflect.Value.call({0x1df2d00?, 0xc000a555d0?, 0x1db3380?}, {0x203d311, 0x4}, {0xc0027081e0, 0x3, 0x260d640?})
        /home/kmodi/go/src/reflect/value.go:556 +0x845
reflect.Value.Call({0x1df2d00?, 0xc000a555d0?, 0xc000df40f0?}, {0xc0027081e0, 0x3, 0x3})
        /home/kmodi/go/src/reflect/value.go:339 +0xbf
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.safeCall({0x1df2d00?, 0xc000a555d0?, 0xc00255f890?}, {0xc0027081e0?, 0x260d640?, 0x1e54700?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/funcs.go:368 +0x9d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCall(0xc0028a9b30, {0x202fe60?, 0xc000df40f0?, 0x1?}, {0x1df2d00?, 0xc000a555d0?, 0x4ea726?}, 0x0, {0x2604098, 0xc000cc5230}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:386 +0xb0a
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalFunction(0xc005d4fb30, {0x202fe60?, 0xc000df40f0?, 0xc003caae40?}, 0x47331e?, {0x2604098, 0xc000cc5230}, {0xc000cc28c0, 0x3, 0x4}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:178 +0x39d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCommand(0xc005d4fb30, {0x202fe60?, 0xc000df40f0?, 0xc004afe000?}, 0x0?, {0x1df64e0?, 0x36e21d8?, 0x1247db3?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:488 +0xea
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalPipeline(0xc0028a9b30, {0x202fe60?, 0xc000df40f0?, 0x1d4f6e0?}, 0xc000cc1140)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:457 +0x145
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a9b30, {0x202fe60?, 0xc000df40f0?, 0xc00255f890?}, {0x2603f30?, 0xc000cc5290})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:261 +0x225
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028a9b30, {0x202fe60?, 0xc000df40f0?, 0x0?}, {0x2604290?, 0xc000cc4d50?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*Template).executeWithState(0x26017f0?, 0xc000142000?, {0x202fe60?, 0xc000df40f0?, 0x202fe60?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:136 +0x135
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*executer).ExecuteWithContext(0xc000a7e310, {0x26017f0, 0xc000142000}, {0x7f359b5a8248, 0xc000c100f0}, {0x25f01c0, 0xc0049f7350}, {0x202fe60, 0xc000df40f0})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:101 +0x345
github.com/gohugoio/hugo/tpl/tplimpl.(*templateExec).ExecuteWithContext(0xc000809350, {0x26017f0, 0xc000142000}, {0x25fa9f0?, 0xc000c100f0}, {0x25f01c0, 0xc0049f7350}, {0x202fe60, 0xc000df40f0})
        /home/kmodi/downloads/git/hugo/tpl/tplimpl/template.go:258 +0x59e
github.com/gohugoio/hugo/tpl/tplimpl.(*templateExec).Execute(0x36525e0?, {0x25fa9f0?, 0xc000c100f0?}, {0x25f01c0?, 0xc0049f7350?}, {0x202fe60?, 0xc000df40f0?})
        /home/kmodi/downloads/git/hugo/tpl/tplimpl/template.go:230 +0x65
github.com/gohugoio/hugo/hugolib.executeToString({0x26062c0, 0xc000809350}, {0x25fa9f0, 0xc000c100f0}, {0x202fe60, 0xc000df40f0})
        /home/kmodi/downloads/git/hugo/hugolib/page__per_output.go:719 +0x102
github.com/gohugoio/hugo/hugolib.(*pageContentOutput).Render(0xc00137cfc0, {0xc00384d360?, 0x4?, 0x0?})
        /home/kmodi/downloads/git/hugo/hugolib/page__per_output.go:480 +0xdd
reflect.Value.call({0x202fe60?, 0xc000df40f0?, 0xc005d50640?}, {0x203d311, 0x4}, {0xc0025690f8, 0x1, 0xc005d50b00?})
        /home/kmodi/go/src/reflect/value.go:556 +0x845
reflect.Value.Call({0x202fe60?, 0xc000df40f0?, 0xc00384d320?}, {0xc0025690f8, 0x1, 0x1})
        /home/kmodi/go/src/reflect/value.go:339 +0xbf
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.safeCall({0x202fe60?, 0xc000df40f0?, 0xc00384d320?}, {0xc0025690f8?, 0x260d640?, 0x1d4f6e0?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/funcs.go:368 +0x9d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCall(0xc0028ab2f0, {0x2012d20?, 0xc00384d320?, 0x8?}, {0x202fe60?, 0xc000df40f0?, 0x4?}, 0x0, {0x26041b8, 0xc001ac6390}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:386 +0xb0a
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalField(0xc005d512f0, {0x2012d20?, 0xc00384d320?, 0xc00384d330?}, {0xc000cc6b61, 0x6}, {0x26041b8, 0xc001ac6390}, {0xc002412f60, 0x2, ...}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:223 +0x55c
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalFieldChain(0x2f000000021f8870?, {0x2012d20?, 0xc00384d320?, 0xc0011cdfb0?}, {0x2012d20?, 0xc00384d320?, 0xc006663aa0?}, {0x26041b8, 0xc001ac6390}, {0xc001ffc080, ...}, ...)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:591 +0x1eb
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalFieldNode(0x13?, {0x2012d20?, 0xc00384d320?, 0x2601860?}, 0xc005d50ce8?, {0xc002412f60?, 0xc005d50e18?, 0x124f32e?}, {0x1df64e0, 0x36e21d8, ...})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:555 +0xce
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCommand(0xc005d512f0, {0x2012d20?, 0xc00384d320?, 0xc000a54eb0?}, 0xc0011cdfb0?, {0x1df64e0?, 0x36e21d8?, 0x5?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:483 +0x296
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalPipeline(0xc0028ab2f0, {0x2012d20?, 0xc00384d320?, 0x99?}, 0xc0063fd7a0)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:457 +0x145
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028ab2f0, {0x2012d20?, 0xc00384d320?, 0x1244295?}, {0x2603f30?, 0xc001ac6510})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:261 +0x225
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028ab2f0, {0x2012d20?, 0xc00384d320?, 0x202fe60?}, {0x2604290?, 0xc001ac6300?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkRange.func2({0x1d4ed20?, 0x34a5a60?, 0xc0011cdfb0?}, {0x2012d20?, 0xc00384d320?, 0xc005d512f0?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:373 +0x17d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkRange(0xc005d512f0, {0x202fe60?, 0xc0011cdfb0?, 0xc0011cdfb0?}, 0xc001a9cf40)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:381 +0x573
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc005d512f0, {0x202fe60?, 0xc0011cdfb0?, 0x202fe60?}, {0x26043b0?, 0xc001a9cf40?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:277 +0x28d
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028ab2f0, {0x202fe60?, 0xc0011cdfb0?, 0x0?}, {0x2604290?, 0xc00211b020?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walkTemplate(0xc005d515c8, {0x202fe60?, 0xc0011cdfb0?, 0x1d4f6e0?}, 0xc0056b4340)
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:439 +0x279
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc005d515c8, {0x202fe60?, 0xc0011cdfb0?, 0x3?}, {0x2604440?, 0xc0056b4340?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:279 +0x119
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).walk(0xc0028ab5c8, {0x202fe60?, 0xc0011cdfb0?, 0x0?}, {0x2604290?, 0xc0045f7410?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/exec.go:274 +0x415
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*Template).executeWithState(0x26017f0?, 0xc000142000?, {0x202fe60?, 0xc0011cdfb0?, 0x202fe60?})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:136 +0x135
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*executer).ExecuteWithContext(0xc000a7e310, {0x26017f0, 0xc000142000}, {0x7f359b5a8248, 0xc0023ec780}, {0x25f01c0, 0xc0037b77d0}, {0x202fe60, 0xc0011cdfb0})
        /home/kmodi/downloads/git/hugo/tpl/internal/go_templates/texttemplate/hugo_template.go:101 +0x345
github.com/gohugoio/hugo/tpl/tplimpl.(*templateExec).ExecuteWithContext(0xc000809350, {0x26017f0, 0xc000142000}, {0x25fa9f0?, 0xc0023ec780}, {0x25f01c0, 0xc0037b77d0}, {0x202fe60, 0xc0011cdfb0})
        /home/kmodi/downloads/git/hugo/tpl/tplimpl/template.go:258 +0x59e
github.com/gohugoio/hugo/tpl/tplimpl.(*templateExec).Execute(0x93f6cc?, {0x25fa9f0?, 0xc0023ec780?}, {0x25f01c0?, 0xc0037b77d0?}, {0x202fe60?, 0xc0011cdfb0?})
        /home/kmodi/downloads/git/hugo/tpl/tplimpl/template.go:230 +0x65
github.com/gohugoio/hugo/hugolib.(*Site).renderForTemplate(0x2?, {0x203fae5, 0x4}, {0x203d64d?, 0x203d64d?}, {0x202fe60?, 0xc0011cdfb0?}, {0x25f01c0?, 0xc0037b77d0?}, {0x25fa9f0, ...})
        /home/kmodi/downloads/git/hugo/hugolib/site.go:1820 +0x92
github.com/gohugoio/hugo/hugolib.(*Site).renderAndWritePage(0xc00097db00, 0xc000119690, {0xc0052bb710, 0xf}, {0xc00141a7e0, 0x1b}, 0xc0011cdfb0, {0x25fa9f0, 0xc0023ec780})
        /home/kmodi/downloads/git/hugo/hugolib/site.go:1737 +0x2c8
github.com/gohugoio/hugo/hugolib.pageRenderer(0x122b925?, 0xc00097db00, 0xc000ac9fd0?, 0x122b8a6?, 0xc000568480?)
        /home/kmodi/downloads/git/hugo/hugolib/site_render.go:138 +0x287
created by github.com/gohugoio/hugo/hugolib.(*Site).renderPages
        /home/kmodi/downloads/git/hugo/hugolib/site_render.go:74 +0x108
```
</details>

### Steps to reproduce this

```
git clone https://gitlab.com/kaushalmodi/kaushalmodi.gitlab.io test
cd test
git checkout hugo-issue-9959
hugo --buildDrafts # or hugo server --buildDrafts
```

### Other info

1. This panic doesn't happen if `--buildDrafts` is not used.
2. This panic doesn't happen even when I switch back to v0.99.1 and use `--buildDrafts`.


Discussion / hints:
I was able to narrow down the crash to the use of (i) `.RawContent | markdownify` in one of my template files, and (ii) use of the `figure` shortcode in a content file.

![image](https://user-images.githubusercontent.com/3578197/171253626-cd74273c-0d6b-467c-ad84-d33bd569c6a3.png)


Here's a recipe with a much smaller codebase:

```
git clone https://gitlab.com/hugo-mwe/hugo-mwe
cd hugo-mwe
git checkout builddrafts-panic
hugo server --buildDrafts
```

Relevant commit: https://gitlab.com/hugo-mwe/hugo-mwe/-/commit/6f3a5cf71bd7d34f4829e5d8d3afb6d5c033d449

### Workaround to prevent the crash

Use `$.RenderString` instead of `markdownify`.
Same here. Unfortunately I can't use workaround because `markdownify` is used in PaperMod theme. I get 6 errors when I start server.. And I can't rollback since `brew` does not provide versioned formulas 😩 
> Unfortunately I can't use workaround because markdownify is used in PaperMod theme.

You can override the partials and theme files in your site's layouts/ directory until this get fixed in Hugo.
@kaushalmodi 

`markdownify` has been effectively aliased to `site.Home.RenderString` since v0.93.0.

With both of the test sites that you reference in this issue, the home page is not backed by a content file. I think you can work around this issue with:

```
hugo new _index.md
``` 
I will fix this and push a patch release later today.

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index c6522809efe..7e6b6e67040 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -163,8 +163,6 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB
 		},
 	}
 
-	ps.shortcodeState = newShortcodeHandler(ps, ps.s)
-
 	if err := ps.mapContent(parentBucket, metaProvider); err != nil {
 		return nil, ps.wrapError(err)
 	}
diff --git a/hugolib/page__common.go b/hugolib/page__common.go
index e55bb7e253c..59f0bc77605 100644
--- a/hugolib/page__common.go
+++ b/hugolib/page__common.go
@@ -102,6 +102,9 @@ type pageCommon struct {
 	// The parsed page content.
 	pageContent
 
+	// Keeps track of the shortcodes on a page.
+	shortcodeState *shortcodeHandler
+
 	// Set if feature enabled and this is in a Git repo.
 	gitInfo    *gitmap.GitInfo
 	codeowners []string
diff --git a/hugolib/page__content.go b/hugolib/page__content.go
index 5871884545d..bf69fafcda4 100644
--- a/hugolib/page__content.go
+++ b/hugolib/page__content.go
@@ -33,8 +33,6 @@ type pageContent struct {
 
 	cmap *pageContentMap
 
-	shortcodeState *shortcodeHandler
-
 	source rawPageContent
 }
 
diff --git a/hugolib/page__new.go b/hugolib/page__new.go
index 897c0281b23..e52b9476b03 100644
--- a/hugolib/page__new.go
+++ b/hugolib/page__new.go
@@ -66,6 +66,8 @@ func newPageBase(metaProvider *pageMeta) (*pageState, error) {
 		},
 	}
 
+	ps.shortcodeState = newShortcodeHandler(ps, ps.s)
+
 	siteAdapter := pageSiteAdapter{s: s, p: ps}
 
 	ps.pageMenus = &pageMenus{p: ps}
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 2bf16dd9ee6..e69d32e27a6 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -25,7 +25,6 @@ import (
 
 	"errors"
 
-	"github.com/gohugoio/hugo/common/herrors"
 	"github.com/gohugoio/hugo/common/text"
 	"github.com/gohugoio/hugo/common/types/hstring"
 	"github.com/gohugoio/hugo/identity"
@@ -334,7 +333,6 @@ func (p *pageContentOutput) WordCount() int {
 }
 
 func (p *pageContentOutput) RenderString(args ...any) (template.HTML, error) {
-	defer herrors.Recover()
 	if len(args) < 1 || len(args) > 2 {
 		return "", errors.New("want 1 or 2 arguments")
 	}


Test patch:
diff --git a/hugolib/renderstring_test.go b/hugolib/renderstring_test.go
index d2f453c3303..1be0cdffb53 100644
--- a/hugolib/renderstring_test.go
+++ b/hugolib/renderstring_test.go
@@ -158,5 +158,35 @@ Page Type: *hugolib.pageForShortcode`,
 		)
 
 	})
+}
+
+// Issue 9959
+func TestRenderStringWithShortcodeInPageWithNoContentFile(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- config.toml --
+-- layouts/shortcodes/myshort.html --
+Page Kind: {{ .Page.Kind }}
+-- layouts/index.html --
+Short: {{ .RenderString "{{< myshort >}}" }}
+Has myshort: {{ .HasShortcode "myshort" }}
+Has other: {{ .HasShortcode "other" }}
+
+	`
+
+	b := NewIntegrationTestBuilder(
+		IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+		},
+	).Build()
+
+	b.AssertFileContent("public/index.html",
+		`
+Page Kind: home
+Has myshort: true
+Has other: false
+`)
 
 }