You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TOC should render statically analyzable embedded expressions in headings (esp. imported partials) #9772
difficulty: advancedIssues that are complex, e.g. large scoping for long-term maintainability.domain: markdownRelated to Markdown parsing or syntaxfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.
I have read the console error message carefully (if applicable).
Description
If a prop is passed to a partial Markdown file, then the ToC displays {props.propname}, instead of the actual value.
As @slorber pointed out in #9684, this is a known limitaion that stems from that even in non-partial files headings don't support expressions.
While having expressions in non-partial headings is a feature, that would be nice for completeness, it's probably not too practical. On the other hand, having expressions in headings of partials can be very useful.
Reproducible demo
No response
Steps to reproduce
Create a partial file that uses a prop in a heading
I don't think it's possible to solve in a generic way without us rendering the whole page, but we might be able to solve a few specific and statically analyzable cases. Maybe if the heading contains expressions, we should export the TOC like export toc = (props) => [`Some ${props.propname} value`] and then in the main file export toc = [..._toc1({ propname: "foo" })]?
changed the title [-]Props passed to partials will not appear in the ToC if used in a heading.[/-][+]TOC should render interpolated expressions in headings[/+]on Mar 3, 2024
changed the title [-]TOC should render interpolated expressions in headings[/-][+]TOC should render statically analyzable embedded expressions in headings[/+]on Mar 3, 2024
changed the title [-]TOC should render statically analyzable embedded expressions in headings[/-][+]TOC should render statically analyzable embedded expressions in headings (esp. imported partials)[/+]on Mar 3, 2024
We should rather pass the props to all MDX and all React components toc(props) function.
Wondering if the "root" (non partial) MDX doc should still export a toc constant or a function. If toc is always a function, this might feel a bit awkward to have to call that function in the theme? 🤷♂️
One interesting thing with a function is that maybe it opens the door to "dynamic TOCs" where TOC items can be different if headings are in tabs for example? 🤔
Note: another discussion requesting support for JSX expressions in TOC: #10353
difficulty: advancedIssues that are complex, e.g. large scoping for long-term maintainability.domain: markdownRelated to Markdown parsing or syntaxfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Activity
Josh-Cena commentedon Mar 3, 2024
I don't think it's possible to solve in a generic way without us rendering the whole page, but we might be able to solve a few specific and statically analyzable cases. Maybe if the heading contains expressions, we should export the TOC like
export toc = (props) => [`Some ${props.propname} value`]and then in the main fileexport toc = [..._toc1({ propname: "foo" })]?[-]Props passed to partials will not appear in the ToC if used in a heading.[/-][+]TOC should render interpolated expressions in headings[/+][-]TOC should render interpolated expressions in headings[/-][+]TOC should render statically analyzable embedded expressions in headings[/+][-]TOC should render statically analyzable embedded expressions in headings[/-][+]TOC should render statically analyzable embedded expressions in headings (esp. imported partials)[/+]slorber commentedon Mar 4, 2024
👍
That's also the idea I had in mind to support React components usage in TOC:
#3915 (comment)
#9773
We should rather pass the props to all MDX and all React components
toc(props)function.Wondering if the "root" (non partial) MDX doc should still export a
tocconstant or a function. Iftocis always a function, this might feel a bit awkward to have to call that function in the theme? 🤷♂️One interesting thing with a function is that maybe it opens the door to "dynamic TOCs" where TOC items can be different if headings are in tabs for example? 🤔
Note: another discussion requesting support for JSX expressions in TOC: #10353