No table of contents from partial calling separate markdown files

I have a site page written in markdown that includes YAML list data as follows:

---
title: "Week 1"
type: book
components:
  - style: Moore v California
    file: moore.md
    _template: case
---

And I have a partial layout for publishing that markdown file that also pulls content from other .md files in the site:

{{ $headless := .Site.GetPage "/courses/property/cases" }}
            {{ range .Params.Components }}
              {{ if eq ._template "case"}}
                {{ $file := print .file }}
                {{ $reusablePages := $headless.Resources.Match $file }}
                {{ range $reusablePages }}<h2>{{ .Params.style }}</h2>{{ end }}
               {{ range $reusablePages }}{{ .Content }}{{ end }}
              {{ end }}
            {{ end }}

This works to pull the markdown content, but neither the headings in moore.md nor those created in the partial (using <h2>) appear in the table of contents (using {{ .TableOfContents }}).

Is there a way to include these headings in the TOC?

(Thank you – this is my first post for support).

No. The HTML rendered by the .TableOfContents method is derived from the page’s .Content.

layouts/_default/single.html

{{ .TableOfContents }}
{{ .Content }}                <-- headings included in TOC
{{ partial "other.html" . }}  <-- headings not included in TOC

If you want to pull additional markdown into a page’s .Content you will need to use a shortcode, invoking it with the {{% my-shortcode %}} notation.

You can replace the standard hugo table of contents with a javascript-based solution, that also solves the problem.