Replies: 2 comments 1 reply
-
Hello @mgriff88,
As per the documentation the recommended/the least invasive way to add JavaScript is to use a You can use something like this to change all of the TOC elements: for (const el of document.querySelectorAll('[data-md-type="toc"] .md-typeset')) {
el.innerHTML = "123";
} However, this is JavaScript code that runs after the page is rendered, so if there is a delay in processing it then users will see the changes happening in real time (removal of the If you want to change it directly in HTML during the source creation process, you'll need to work with Python or templates. The TOC is attached to the You could edit it in for example in the on_page_context event.
If you accept the idea of overriding a template and replacing it then you could try modifying the TOC item content inside the template: I didn't check if |
Beta Was this translation helpful? Give feedback.
-
Hi @kamilkrzyskow , thanks for the detailed response! I'm all for overriding a template, unfortunately that replace() filter isn't working quite right... I've tried adding tags around the text I want to remove too, but still not working. When I ask ChatGPT about this, it says I need to add Python instead. Any guidance on where to place custom .py file? |
Beta Was this translation helpful? Give feedback.
-
I have a particular use case where I am placing tags within a heading. I want the text from the heading to appear in the page TOC, but not the tag itself.
This is the Markdown:
### alertsSearchQuery [String](#string){: .api-tag}
And it looks like this:
Body:
TOC:
In this example,
alertsSearchQuery
is the h3 part, butString
is from the tag and I don't want it to appear there.My idea is to write a Javascript function for use in toc-item.html partial that strips out any characters that appear between [ and }. Can someone explain to me how I can get Material to register that function? I've tried placing the JS file in overrides and adding it as a plugin or a markdown_extension, but it's never able to find it, and I just get serve errors.
TL;DR: Where do you place custom Javascript in Material?
Beta Was this translation helpful? Give feedback.
All reactions