Add word/line break option `<wbr />`
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 ­ a hyphen will be added.
| Desktop (no issues) | Mobile (Wrong word/line break) |
|---|---|
| The correct word break in this word would be "Verpackungs- lösungen" |
What is your proposed solution?
Adding a option for line break or word break
Not sure if "(invisible)" is the best wording.
This is very important for making Gutenberg more attractive to non-english speaker.
+1 from me. We get through this also a lot and would appreciate a solution :)
For everyone reading this how to break words manually until this feature exist:
- Go to the Code editor and search for the word
- Add either
­(word break with hyphen) or<wbr />(without)
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
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.
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?
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 ­ shouldn't be added to the link.
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.
Note: there is also an issue about proposing to add the word-break option: https://github.com/WordPress/gutenberg/issues/11956
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 ­
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!
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!
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.
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. 😃
I am not sure this needs design, so let's for now have it move back to feedback.
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?
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.
😄
it seems like there’s no objective break opportunity in the word, unless you are proposing that the break should fall at Guten
berg?
Correct, this was my thinking.
Interestingly, Merriam Webster displays word breaks with a dot: Gu·ten·berg
https://www.merriam-webster.com/dictionary/Gutenberg
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 |
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 :)