Skip to content

Format Library: Add formatting options for word break and soft hyphen - #71521

Open
BugReportOnWeb wants to merge 2 commits into
WordPress:trunkfrom
BugReportOnWeb:feat/word-break-options
Open

BugReportOnWeb wants to merge 2 commits into
WordPress:trunkfrom
BugReportOnWeb:feat/word-break-options

Conversation

@BugReportOnWeb

Copy link
Copy Markdown
Contributor

What?

Closes #55565

This PR introduces two new inline formatting options to the editor:

  • Word break (<wbr>): allows manual control of where a long word may break without inserting visible characters.
  • Soft hyphen (&shy;): adds a discretionary hyphen that only appears at line breaks.

Why?

In some languages, long words often break incorrectly on smaller screens. Adding options for <wbr> and &shy; gives authors precise control over word breaking, improving readability across devices and languages.

How?

  • Added a new line-break format module format library.
  • Registered two new formats:
    • core/line-break-wbr: inserts <wbr> at the caret position
    • core/soft-hyphen: inserts a soft hyphen (\u00AD) at the caret position.

Testing Instructions

  1. Create or edit a post with a Paragraph or a Heading block.
  2. Place the cursor inside a long word
  3. Open the inline formatting dropdown
  4. Select Insert word break or Insert soft hyphen.
    • In the editor, nothing visible may appear if on a desktop view.
    • Switch to the Code editor view -> <wbr> or &shy; should be inserted at the cursor position.
    • On the smaller screens (editor and frontend), text should break correctly:
      • <wbr>: line may break without hyphen.
      • &shy;: line may break with hyphen shown.

Screenshots or screencast

Screen.Recording.2025-09-05.at.6.50.43.PM.mov

@BugReportOnWeb
BugReportOnWeb marked this pull request as ready for review September 7, 2025 12:31
@github-actions

github-actions Bot commented Sep 7, 2025 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @senicar.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: senicar.

Co-authored-by: BugReportOnWeb <devasheeshkaul@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>
Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: karmatosed <karmatosed@git.wordpress.org>
Co-authored-by: dmsnell <dmsnell@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Package] Format library /packages/format-library labels Sep 11, 2025
@jasmussen

Copy link
Copy Markdown
Contributor

Thank you for contributing. I know this is an older PR, but I'm wondering if there's a way to resurrect it, as it's relatively small and simple. I'm not personally convinced we should add both the soft hyphen and the wbr glyphs, it seems like the latter offers the more easy to understand user experience. But as a relatively simple PR it might be a nice addition.

CC: @WordPress/gutenberg-design for a fresh look.


One longer term perspective is to also address #31401.

The big challenge we have is that we risk making the inline format library grow very long. Today it looks like this:

image

If we add three new menu items, the menu can grow quite long. However one thing we could possibly do, is refactor this menu to use the new Menu component. What this would offer is the ability to create submenus. We could add to the inline formatting library a submenu called "Special character", which would contain both wbr, soft hyphen, nonbreakingspace, and so on.

There's a question of the black border of block toolbar submenus to address as part of that, but that's a challenge worth considering regardless.

@masteradhoc

Copy link
Copy Markdown
Contributor

Thank you for the work here @BugReportOnWeb ! +1 from my side to get this merged

@hanneslsm

Copy link
Copy Markdown

We could add to the inline formatting library a submenu called "Special character", which would contain both wbr, soft hyphen, nonbreakingspace, and so on.

I think this is a great idea!

@aduth

aduth commented Aug 26, 2026

Copy link
Copy Markdown
Member

Hey 👋 I wanted to give you a heads-up since this pull request adds new files containing JSX.

#80123 enables an ESLint rule that requires that files containing JSX must use the .tsx file extension. This is in line with coding guidelines expecting new code to be written as TypeScript.

What you'll need to do: You'll need to rename any new files containing JSX to use the .tsx file extension. This may also require you to address type errors that were not previously caught due to the use of the .js file extension.

This comment is automated, based on pull requests with recent activity that contain affected .js or .jsx files. But if you have any questions or if I can help with the migration in any way, please let me know and I'll do my best to help!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Format library /packages/format-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add word/line break option <wbr />

6 participants