VSCode extension to auto-add id attribute to section headers and create table of contents in HTML; Using it for Blogger blog posts/pages
Quick-Info
Details
Background Info including AI chat extracts
As you have discovered, inserting a named anchor to create a jump link requires adding an id attribute, and Blogger's visual editor does not provide a simple button for this. The only reliable way to add an ID is to switch to the HTML view and insert it manually.
Is there some free plug-in for Blogger that provides this functionality to add an ID (named anchor) to a section heading without having to edit the HTML
As a self-contained platform, Blogger does not support external "plugins" in the same way that WordPress does. Any third-party tools that automate functions like adding id attributes would involve editing the core HTML template of your blog, which is a more advanced process than simple HTML editing within a post. There is no official or widely available free tool that can add named anchors in Blogger's visual editor.
I guess manual editing is safer than all this JS code insertion stuff.
To ease manual editing, I can copy the HTML code of the blog post into VSCode, use Prettier or some extension like that to bring in some line breaks formatting for the typically one long string that Blogger generates for post conent, and use VSCode's superior features to add id attributes to required elements.
--------------------
Me (to ChatGPT in same chat, ''Blogger: Creating internal links easily", 2 Sep. 2025): If I need this on regular basis, one possibility is using a JS library like Tocbot ***offline***. By that I mean, extracting the HTML of a post (manually or programmatically), run Tocbot on it to get a modified HTML which has id attributes attached to header sections, and save this file as a separate file. Next step I can use VSCode's file comparison feature to confirm that all changes made by Tocbot in the saved file are OK. If so, then I can copy paste that file's content into the blog post overwriting its HTML. Advantage of this as compared to invoking the Tocbot JS code inline in a post, is that in the latter case, under some circumstances, the JS code may not correctly update the HTML. Your views on above please.
ChatGPT: That is a very sharp idea and I think you have spotted the key distinction:
-
Inline/Template JS (Tocbot in Blogger) → runs at page load in the browser of the reader.
-
Pros: Automatic.
-
Cons: If the script fails (JS disabled, Blogger theme conflicts, script update issues), your post still has no IDs in the underlying HTML → links break.
-
-
Offline pre-processing with Tocbot (your idea) → you generate the IDs once on your local machine, verify them, and paste the final HTML back into Blogger.
-
Pros:
-
No runtime dependency.
-
Your published HTML has the IDs baked in → stable forever.
-
You can visually review the changes in VSCode (diff tool).
-
-
Cons:
-
Extra workflow step (extract → run Tocbot → verify → paste).
-
Still manual to some degree.
-
-
Why your offline approach is safer
-
Deterministic output → What you paste into Blogger is exactly what readers see.
-
No chance of runtime breakage → Even if a browser blocks JS or Blogger changes its template handling.
-
Easy verification → File diff ensures Tocbot did not do anything unexpected.
-
No external dependencies → After pasting, the post is self-contained.
This is exactly how some technical bloggers handle things: they pre-process posts with tools (Pandoc, Markdown → HTML converters, TOC generators) and only publish "final HTML".
Suggested Workflow
-
Export Blogger post HTML.
-
Run a local script with Tocbot (Node.js or even a small HTML+JS runner).
-
Save the modified HTML → open side-by-side with original in VSCode → confirm IDs.
-
Paste back into Blogger's HTML editor.
My view
Your plan is much better than inline JS hacks if
stability is your top priority.
It's basically turning Tocbot
into a pre-publish tool, instead of a
live script.
This gives you
WordPress-like TOC/IDs while staying in Blogger.
------------------
Comments
Post a Comment