gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Add word/line break option `<wbr />`

Open hanneslsm opened this issue 3 years ago • 17 comments

What problem does this address?

Some words are too long, so they will break on mobile (even with fluid typography). Unfortunately, the word break can be incorrect. With the wbr Tag it's possible to control where the word will break. With &shy; a hyphen will be added.

Desktop (no issues) Mobile (Wrong word/line break)
Image Image
The correct word break in this word would be "Verpackungs- lösungen"
Image

What is your proposed solution?

Adding a option for line break or word break Not sure if "(invisible)" is the best wording. image

This is very important for making Gutenberg more attractive to non-english speaker.

hanneslsm avatar Oct 24 '23 11:10 hanneslsm

+1 from me. We get through this also a lot and would appreciate a solution :)

masteradhoc avatar Oct 25 '23 13:10 masteradhoc

For everyone reading this how to break words manually until this feature exist:

  1. Go to the Code editor and search for the word
  2. Add either &shy; (word break with hyphen) or <wbr /> (without)

hanneslsm avatar Oct 28 '23 12:10 hanneslsm

I wonder if using a global setting like #55190 better resolves this. Adding these formats to each header looks like tedious work, IMO.

Question: Similar text styling seems like a language-specific feature. I wonder if the requested custom format would be better suited for a plugin.

cc @WordPress/gutenberg-design

Mamaduka avatar Sep 07 '25 03:09 Mamaduka

It's also important to note that some languages ​​don't use soft hyphens at all.

Japanese, for example, doesn't have spaces between words and doesn't use hyphens even when words are wrapped.

t-hamano avatar Sep 07 '25 09:09 t-hamano

It's unclear to me that text-wrap, for the reasons Aki mentions, will work for this. I still think we want text wrap, to be clear, but not sure it's a bulletproof solution.

So the question is first whether this is plugin territory or of core importance: I have no strong opinion there so happy to hear some consensus from the group there. Secondly if it's core territory, finding an interface to add this. And there really are a few ways this can go:

  • The inline dropdown as proposed makes sense as it handles prominence, so the tricky part is what to call the item, and what item to give it. But we wouldn't want anyone to use this character instead of pressing Enter or Shift Enter to make real linebreaks. Its behavior is pretty hard to explain.
  • Speaking of, shift enter is the way to create a <br> tag—the only way. This character does seem a bit different than a single linebreak, so perhaps a shortcut (⌥ ⇧ Enter) may not be right, but still something to consider.

The final piece is whether this character should show anything in the canvas. It's a pretty exotic character, you might add it and forget you did.

Perhaps a contrarian proposal, so think of this more of a brainstorming aspect: what if this was a button that existed only in the code editor?

jasmussen avatar Sep 08 '25 12:09 jasmussen

Another solution could be that we add a global setting to the typography elements, making selecting the relatively new hyphens: auto; available: https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens This way, the words would break at least correctly within the word. The downside is that it is that not all languages are supported by every browser yet. We would need to add at least an info text.


Regarding the manual soft hyphen:

So the question is first whether this is plugin territory or of core importance:

I think it's core, because it's essential for some languages (like German and others with long words). The fact that it's part of ISO 8859-1 already since 1986 underlines it's importance. The logical evolution then though would be, with also considering Phase 4 of Gutenberg already, adding a special character inserter someday.

Perhaps a contrarian proposal, so think of this more of a brainstorming aspect: what if this was a button that existed only in the code editor?

I like this thinking! The code editor is currently much underutilized anyway. Content Mode, Freeflow mode and Coding mode (with syntax highlighting, inserting special characters, [maybe even with AI autocomplete] et cetera). There's potential. Sounds like a lot of work though 😄

The final piece is whether this character should show anything in the canvas. It's a pretty exotic character, you might add it and forget you did.

The first that comes to mind is that the soft hyphen character will be displayed as an overlay like in InDesign.


Another thing to consider when implementing the soft hyphen feature are anchor links. They links should break, but the &shy; shouldn't be added to the link.

hanneslsm avatar Sep 08 '25 17:09 hanneslsm

The final piece is whether this character should show anything in the canvas. It's a pretty exotic character, you might add it and forget you did.

That's one issue I ran into while working on this. The word break only happens on smaller screens, which means it inserts invisible content. Because of this, it’s hard to toggle it off once added, and the only way to remove it is by undoing the action, which can easily get lost in the undo history if many other changes are made.

While users can still check the code editor to find and remove it, that makes the removal process much less intuitive.

BugReportOnWeb avatar Sep 09 '25 06:09 BugReportOnWeb

Note: there is also an issue about proposing to add the word-break option: https://github.com/WordPress/gutenberg/issues/11956

t-hamano avatar Sep 09 '25 13:09 t-hamano

The word break only happens on smaller screens, which means it inserts invisible content.

To that specific statement: not necessarily only on smaller screens, also often in titles. Example: The privacy policy on one of my clients website https://www.bittner-krull.de/datenschutz/ where I had to manually add the &shy;

Image

hanneslsm avatar Sep 09 '25 14:09 hanneslsm

What @hanneslsm writes here is quite a well known limitation. we have to use this by default for h1,h2,h3 headings and sometimes for p. The Quickedit option works as long as no client saves the page but a solution like discussed here would be amazing to get!

masteradhoc avatar Sep 09 '25 14:09 masteradhoc

I just saw another example today on WordPress.org of why this is needed. I'm adding a 'needs design' label. If anyone has ideas for how to visualise invisible characters, suggestions are very welcome!

Image

hanneslsm avatar Sep 16 '25 18:09 hanneslsm

I just saw another example today on WordPress.org of why this is needed.

That's a good flag, but I think that's arguably a reason for fluid typography so the font size isn't so big that it wraps.

jasmussen avatar Sep 18 '25 11:09 jasmussen

I just saw another example today on WordPress.org of why this is needed.

That's a good flag, but I think that's arguably a reason for fluid typography so the font size isn't so big that it wraps.

There is always a German word that you just cannot make it "fluid" and simply requires a hyphenated line break. 😃

senicar avatar Sep 25 '25 08:09 senicar

I am not sure this needs design, so let's for now have it move back to feedback.

karmatosed avatar Sep 30 '25 09:09 karmatosed

I just closed a related issue in https://github.com/WordPress/gutenberg/issues/31401#issuecomment-5407893291, I'm tempted to close this one for the same reason: it's good plugin territory but it's unclear that it should be directly supported in the core product. Also note, there's a PR in #74040 that makes invisible characters visible, worth looking at as it's related.

However, there's a PR in process to address this in #71521. If folks subscribed reviewed that PR, we could possibly unblock it and get some momentum. What do you think?

jasmussen avatar Aug 25 '26 09:08 jasmussen

I just saw another example today on WordPress.org of why this is needed.

Curious how <wbr> would help here @hanneslsm — it seems like there’s no objective break opportunity in the word, unless you are proposing that the break should fall at Guten<wbr>berg?


Just a note for all: the WBR element is a void element in HTML, which cannot contain content. Therefore it’s preferable to leave of the mistaken “self-closing flag” which is ignored by the HTML parser. That means the canonical rendering is <wbr> and not <wbr/> or <wbr />.

Just a fun fact: this predates XML which created the self-closing flag as syntax-minimization for the SGML null end-tag concept by updating the SGML spec to separate the null end-tag opening from the null end-tag closing delimiters.

In XML, <wbr /> is identical to <wbr></wbr>, which is a wbr element which happens to contain no children — it’s essential a lexer macro. In HTML no such equivalent is possible because the WBR element is content-less; there is no such thing as <wbr></wbr> in HTML.

😄

dmsnell avatar Aug 25 '26 19:08 dmsnell

it seems like there’s no objective break opportunity in the word, unless you are proposing that the break should fall at Gutenberg?

Correct, this was my thinking.

Interestingly, Merriam Webster displays word breaks with a dot: Gu·​ten·​berg https://www.merriam-webster.com/dictionary/Gutenberg Image

This is similar to the idea from above, displaying invisible characters like in InDesign:

The first that comes to mind is that the soft hyphen character will be displayed as an overlay like in InDesign.

Alternatively, Duden (German dictionary) uses a | Image https://www.duden.de/rechtschreibung/Gutenberg

Not sure how helpful this information is, but I think it proofs that there are different way to display such characters in the editor. And that they are needed :)

hanneslsm avatar Aug 26 '26 08:08 hanneslsm