Skip to content

Heading: Keep combining marks in generated anchors - #85096

Merged
Mamaduka merged 6 commits into
WordPress:trunkfrom
ekamran:shifteq/heading-anchor-combining-marks
Oct 27, 2026
Merged

Mamaduka merged 6 commits into
WordPress:trunkfrom
ekamran:shifteq/heading-anchor-combining-marks

Conversation

@ekamran

@ekamran ekamran commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

Heading Before After
हिंदी व्याकरण ह-द-व-य-करण हिंदी-व्याकरण
தமிழ் மொழி தம-ழ-ம-ழ தமிழ்-மொழி
বাংলা ভাষা ব-ল-ভ-ষ বাংলা-ভাষা
Crème Brûlée, typed with decomposed accents cre-me-bru-le-e creme-brulee
Getting Started getting-started getting-started

How?

getSlug() now returns cleanForSlug( getTextWithoutMarkup( content ) ). Since #84896, cleanForSlug() matches core's sanitize_title(), so anchors follow the same rules as post slugs. Block-library no longer uses remove-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.
  • Apostrophes are removed instead of becoming hyphens, so What's new? becomes whats-new instead of what-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

  1. Turn on anchor generation with this must-use plugin:
    <?php
    add_filter(
    	'block_editor_settings_all',
    	function ( $settings ) {
    		$settings['generateAnchors'] = true;
    		return $settings;
    	}
    );
  2. Create a post and add Heading blocks with हिंदी व्याकरण, தமிழ் மொழி, বাংলা ভাষা, Crème Brûlée, What's new? and Getting Started.
  3. For each heading, open Advanced and check HTML anchor: the scripts keep their vowel signs as in the After column above, and What's new? gives whats-new.

There is no new unit test: cleanForSlug() is covered by the tests in packages/url.

Testing Instructions for Keyboard

No UI changes.

Screenshots or screencast

wp713-stock-html-anchor fix-typed-html-anchor

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.

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.
@ekamran
ekamran requested a review from fabiankaegy as a code owner October 19, 2026 13:00
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ekamran <ekamran@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Oct 19, 2026
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.
@github-actions github-actions Bot added the [Package] Edit Site /packages/edit-site label Oct 19, 2026
@Mamaduka

Copy link
Copy Markdown
Member

I think we can just use cleanForSlug, it already handles mentioned cases - #84896.

This should reduce custom code noticeably. We can also drop the tests; cleanForSlug has good test coverage.

@Mamaduka Mamaduka added the [Type] Bug An existing feature does not function as intended label Oct 19, 2026
@ekamran

ekamran commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, George. Happy to switch to cleanForSlug. It fixes the Hindi, Tamil and Bengali cases and the decomposed accents the same way.

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: अलग-अलग प्रकार के प्लंबिंग ट्रैप्स और उनके उपयोग के बारे में पूरी जानकारी (73 characters) becomes अलग-अलग-प्रकार-के-प्लंबिं (25). It also changes some English anchors for new headings, for example What's new? becomes whats-new instead of what-s-new, and some emoji, including ❤️, are kept.

If that's fine, I'll switch to cleanForSlug and drop the test, the TypeScript conversion and the tsconfig split.

@Mamaduka

Copy link
Copy Markdown
Member

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.
@github-actions github-actions Bot removed the [Package] Edit Site /packages/edit-site label Oct 19, 2026

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ekamran!

@Mamaduka
Mamaduka merged commit 95862e0 into WordPress:trunk Oct 27, 2026
92 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 27, 2026
@ekamran
ekamran deleted the shifteq/heading-anchor-combining-marks branch October 27, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heading: Generated anchors split words in scripts that use combining marks, such as Hindi, Tamil and Bengali

2 participants