As I personally prefer the look of justified text (with proper hyphenation!) I would love to see the addition of a hyphenation setting to auto-insert ­
(or the equivalent Unicode character!) in text. Unlike hyphenation: auto
(which doesn’t work properly on most browsers), explicit soft hyphens do tend to work. And since a Knuth-Liang hyphenation crate for Rust exists, this should be feasible, right?
I currently build my site using a horrible, hacked together - and insanely slow - mix of Python (templates, markdown processing & hyphenation) and node.js (KaTeX & minimization). So it would be good for my sanity to be able to switch at some point
I warmly recommend the (client-side) Hyphenology library which supports more than just English right out of the box.
I’m not a big fan of doing things client-side that could easily be done on the server (or in this case: before even serving the file). The hyphenation crate also supports more than just English (as long as you have the appropriate dictionary).
Even the 2 KiB for the loader are probably more than the handful of 0xad
-s you would have on a typical page. And the ~22 KiB if the browser doesn’t support it are definitely more.
1 Like
Ah, sorry. I should have checked the repository before posting.
I agree: The crate you mentioned looks very good.
1 Like
I tried inserting the following in markdown_to_html
(possibly not the right place to do this, as page/text language doesn’t seem to be available directly, but it is easier to recognize text or other input here):
// Business as usual
if let Ok(hyphenator) = hyphenation::Standard::from_embedded(
hyphenation::Language::EnglishUS,
) {
Event::Text(
text.split_word_bounds()
.map(|w| {
hyphenator
.hyphenate(w)
.into_iter()
.segments()
.map(|s| {
s.trim_start_matches("\u{00ad}").to_owned()
})
.collect::<Vec<String>>()
.join("\u{00ad}")
})
.collect::<Vec<String>>()
.join("")
.into(),
)
} else {
Event::Text(text)
}
And it works:
1 Like
Just noticed I didn’t post this in “Feature Requests”… is there any way to move the topic?