Add hyphenate breaks at hyphens
- Dominant language
- Haskell
- Stars
- 35
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
I recently used `hyphenation` to add soft hyphens to gwern.net so I could enable fully-justified text on desktop Chrome/Chromium browsers. (Bizarrely, for many years now, Chrome has had hyphenation on mobile Android but *not* desktop, and the devs have dragged their feet with the excuse that they just can't figure out how to ship dictionary files for desktop browsers; I gave up waiting for them to fix it.)
A user reported that [on Safari browsers](https://twitter.com/ctphoenix/status/1323036036813840384), Safari would line-break a hyphen-separated word like "compile-time" but there would be *two* hyphens: the original hyphen and then the smaller line-breaking hyphen, presumably the soft hyphen. Other browsers correctly ignore the soft hyphen and show only the regular hyphen if they need to line-break things like "compile-time". But why was there a soft hyphen there to begin with?
It turns out that `hyphenation` inserts soft hyphens even at existing hyphens!
~~~{.Haskell}
> H.hyphenate H.english_US "Compile-time"
["Com","pile-","time"]
~~~
I would expect instead a breaking like `["Com", "pile-time"]`. There is no need to insert a soft hyphen at the existing hyphen, since that is where a justification algorithm would break anyway. It can only cause problems, and in the case of Safari, does.
My current workaround is a post-processing hack to string-replace any hyphen+soft-hyphen present: `Data.Text.replace "-\173" "-"` etc. But this does other `hyphenation` users no good.
---
On an additional note, it would be nice to have a utility function which takes a String/Text and returns it with soft hyphens inserted. My current implementation goes like this, and it's complex enough that I'm not convinced I'm doing it right:
~~~{.Haskell}
T.pack $ unwords $ map (intercalate "\173" . H.hyphenate H.english_US{H.hyphenatorLeftMin=3}) $ words $ T.unpack s
~~~
(I don't know how much the lack of a native Text version hurts, but I'm sure it does my compile-times no good, anyway.)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the H.hyphenate H.english_US example for “Compile-time” and inspect the hyphenation behavior around existing hyphens. The main change is done when no soft hyphen is inserted at an existing hyphen while normal break behavior remains intact; the optional String/Text utility request is a separate consideration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100