Repository navigation
Heading: Keep combining marks in generated anchors - #85096
Conversation
getSlug() turned anything that is not a letter or a number into a hyphen. Vowel signs, the virama and the anusvara are combining marks, so Hindi, Tamil and Bengali headings got anchors split into fragments, such as ह-द-व-य-करण for हिंदी व्याकरण. Text typed with decomposed accents had the same problem. Keep combining marks, normalize the text to NFC before removeAccents() like @wordpress/url does, and drop emoji variation selectors and enclosing marks so they do not end up in anchors.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
The heading anchor test is the first TypeScript test in block-library, and lint:tsconfig requires a dev project for TypeScript tests. Split the package config as format-library did in WordPress#85032: tsconfig.build.json for src, tsconfig.json for tests, with the references to the package updated. The build project only lists TypeScript files, so convert autogenerate-anchors to TypeScript for the test to import it. Types only, no change in behavior.
|
I think we can just use This should reduce custom code noticeably. We can also drop the tests; |
|
Thanks, George. Happy to switch to One difference to confirm first: it keeps only what fits in 200 percent-encoded characters, and each Devanagari code point takes 9 of those. So a long Hindi heading gets cut, sometimes mid-word: If that's fine, I'll switch to |
|
I think that should be okay, it would be consistent how similar cases are handled in other places. |
Use cleanForSlug() from @wordpress/url for heading anchors, as suggested in review. Since WordPress#84896 it matches core's sanitize_title() and keeps combining marks, so Hindi, Tamil and Bengali headings no longer get anchors split into fragments. Drop the custom slug code and its test, the TypeScript conversion and tsconfig split that the test needed, and the remove-accents dependency, which block-library no longer uses.
What?
Closes #85095
Generated heading anchors now use
cleanForSlug()from@wordpress/url, so headings in scripts like Devanagari, Tamil and Bengali get readable anchors instead of words split by hyphens.Why?
getSlug()turned anything that is not a letter or a number into a hyphen. Vowel signs, the virama and the anusvara are combining marks, so:हिंदी व्याकरणह-द-व-य-करणहिंदी-व्याकरणதமிழ் மொழிதம-ழ-ம-ழதமிழ்-மொழிবাংলা ভাষাব-ল-ভ-ষবাংলা-ভাষাCrème Brûlée, typed with decomposed accentscre-me-bru-le-ecreme-bruleeGetting Startedgetting-startedgetting-startedHow?
getSlug()now returnscleanForSlug( getTextWithoutMarkup( content ) ). Since #84896,cleanForSlug()matches core'ssanitize_title(), so anchors follow the same rules as post slugs. Block-library no longer usesremove-accents, so it is removed from its dependencies.As discussed in the comments, this also changes some anchors for new headings:
cleanForSlug()keeps only what fits in 200 percent-encoded characters, so long headings in scripts like Devanagari get cut. A 73-character Hindi heading becomes a 25-character anchor.What's new?becomeswhats-newinstead ofwhat-s-new, and some emoji, including ❤️, are kept.Anchors saved before this change keep their value. The editor only updates an anchor while it still matches what
generateAnchor()returns for the heading's text, so an anchor generated by the old code is now treated like a custom anchor: editing the heading no longer updates it, and links to it keep working.Testing Instructions
हिंदी व्याकरण,தமிழ் மொழி,বাংলা ভাষা,Crème Brûlée,What's new?andGetting Started.What's new?giveswhats-new.There is no new unit test:
cleanForSlug()is covered by the tests inpackages/url.Testing Instructions for Keyboard
No UI changes.
Screenshots or screencast
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Investigation, implementation, browser verification, review follow-up, and PR wording. I reviewed the reasoning and test results, and I take responsibility for the contribution.