Skip to content

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

Closed

Description

@ekamran

Description

When the editor generates anchors for Heading blocks, combining marks are treated as separators and turned into hyphens. In scripts like Devanagari, Tamil and Bengali, vowel signs, the virama and the anusvara are combining marks (Unicode category M), so the anchor splits every word apart:

Heading Generated anchor Expected
हिंदी व्याकरण ह-द-व-य-करण हिंदी-व्याकरण
தமிழ் மொழி தம-ழ-ம-ழ தமிழ்-மொழி
বাংলা ভাষা ব-ল-ভ-ষ বাংলা-ভাষা

Text typed with decomposed accents (a letter followed by a combining accent such as U+0300) has the same problem. Crème Brûlée typed that way gets cre-me-bru-le-e, while the precomposed form gets creme-brulee.

Anchors are only generated when the generateAnchors editor setting is on, or when the post has a Table of Contents block.

The cause is getSlug() in packages/block-library/src/heading/autogenerate-anchors.js, which turns anything that is not a letter or a number ([^\p{L}\p{N}]) into a hyphen. #84896 fixed this for post slugs (cleanForSlug() now keeps Devanagari vowel signs), but heading anchors are generated by separate code.

Step-by-step reproduction instructions

  1. Turn on anchor generation, for example with this must-use plugin:
<?php
add_filter(
	'block_editor_settings_all',
	function ( $settings ) {
		$settings['generateAnchors'] = true;
		return $settings;
	}
);
  1. Create a new post and add a Heading block.
  2. Type हिंदी व्याकरण.
  3. Open the block settings, then Advanced, and look at HTML anchor.
  4. It shows ह-द-व-य-करण. Expected: हिंदी-व्याकरण.

Screenshots, screen recording, code snippet

Image

Environment info

  • WordPress 7.1.3 without the Gutenberg plugin. The same code is on Gutenberg trunk.
  • Twenty Twenty-Five 1.5.
  • Chromium on macOS.

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Status] In Progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions