Show HN: My project for this weekend (with source)
softhyphen.com
softhyphen.com
Adding these hyphens manually is quite tedious. So I wrote up this little utility that takes HTML and adds soft hyphens automatically.
Background:
- Took a day to write (started it yesterday afternoon)
- Written in Python, deployed on AppEngine
- Uses OpenOffice's hyphenation dictionaries
Source code: http://github.com/fortes/softhyphen
(1) Browser layout engines are pretty messed up, and adding a bunch of shy hyphens can lead to really weird layout issues. I wish I had some good examples, but basically it has to do with taking into account the amount of space a hyphen takes up, and using that to compute how long lines should be, but then when the hyphens are in the middle of the line, not showing them. Anyway, as I remember sometimes it can result in text being eaten (i.e. not shown properly).
In other words, I’d try to do specific testing in a bunch of browsers, resizing a window through all reasonable sizes it might be, before counting on shy hyphens to work properly.
(2) This is still going to break search within pages. Pretty stupid that browsers can’t do proper search, but so it goes.
(3) This is going to be effectively a line-by-line paragraph composer, because browsers don’t do any kind of real paragraph layout. And it still won’t do any adjustment of inter-letter space. The combination of these two things means that using justified text is going to still usually end up looking like crap. Better than without any hyphenation, but not all that much better.
----
In short, this is kind of a half-way stopover workaround for the absolutely stupid lack of real hyphenation and justification algorithms in current browsers. Absolutely stupid because this is a solved problem: the algorithm used by TeX and described in one of Knuth’s students in the late 70s works pretty darn well (Adobe uses a modified version for InDesign), and on modern hardware should be perfectly reasonably fast, as well.
It’s not quite as bad as the lack of real layout in Microsoft Word, given that laying out text is the only purpose of that application, but still.... pretty bad.
Did html5 address this?
But if there is an approximate solution you can create which doesn't require dictionaries, you can port that to javascript as a library which can then instrument all the elements in a class with these soft hyphens. This will also solve the performance issue and can be introduced very unobtrusively into virtually any application.
And also any potential SEO concerns are alleviated.
A relavant Reddit thread - http://j.mp/d8H3Tf
I implemented something similar (soft hyphenation related) some years back and ended up looking into just what you're asking about. My conclusion then was: The big ones act nicely, and that's about where I stopped looking.
A quick Google for "soft hyphens and google" will give a good indication or simply search this page for "google": http://www.cs.tut.fi/~jkorpela/shy.html
OK, so general SEO question. Do search engines trip up after this? Why? Are they parsing HTML straight up or do they have funky rules?
FOR EXAMPLE, I have heard that <h1> gives benefit to enclosed text. i have wondered this: but can u just have jquery automatically replace it on pageload and then get credit for arbitrary keywords while actually presenting the viewer with different phrasing. wouldn't that work?
anyway, couldn't you apply my idea similarly? this would be a really simple jquery plugin
Make pages primarily for users, not for search engines. Don't deceive your users or present different content to search engines than you display to users, which is commonly referred to as "cloaking."
Oh yeah, Google's tech support system sucks btw. Someone would make big bucks if they found a way to make that fun and efficient for their tech support staff. Tech support in general. It's rarely fun to call in to tech support. Shouldn't it be fun? Zappos style. Duuude: SMS text support. Text your initial question, and someone calls you. Kinda like Aardvark except now.
I actually did something similar..
Last year, I started looking at algorithms to count syllables. It turns out that hyphenation and syllable detection have a lot in common.
Anyway, long story short: one of the approaches I use on Haikuist is a hyphenation algorithm.
I'm glad you built softhyphen.com. It's such a fun idea.
(http://haikuist.com: poetic micro-blogging for haiku lovers)
http://github.com/fortes/softhyphen/blob/master/hyphenate_ht...
Maybe also provide a JS listener to remove the gaps before copy?
Frank Liang wrote his Stanford Ph.D. thesis on a hyphenation algorithm that is standard in TeX, and has been adapted to numerous languages. The Thesis is available online at http://www.tug.org/docs/liang/
Your application is both useful and well written. It will be very useful though to have the user specify the width of the column in pixels and the font and have a sample that renders the way it should.
http://nedbatchelder.com/code/modules/hyphenate.html
cool way to see tries in action. (though arguably a language with duck typing makes tries pretty hard to read.)
But hey, your mileage may vary and all that.
(PS. As English is not my native language: Did the latter expression ("your mileage may vary...") perhaps stem from the expression "that extra mile"? Just realized they may be related! Oh well...)
"Your mileage may vary" was a disclaimer on car advertisements (because you never achieve the advertised miles-per-gallon).
"Go the extra mile" is biblical: Matthew 5:41
One could argue that it's language related! Thanks for your answer.:)
The mileage comment was more from the auto manufacturers / EPA who tested cars. A car will have been tested on specific conditions and found to achieve a certain Miles per Gallon. However - accelerate/brake hard, drive more in the city or other different conditions and you would get a completely different result. Hence the standard disclaimer of "your mileage may vary..." That made it's way into the lingo as a standard phrase meaning "this is pretty subjective - it might be the same for you, it might not"
So aside from the word "mileage" being derived from the base word "mile", there isn't much overlap between the two phrases.
(Oh - and a related note for my American friends - as much as I hate imperial units - I will give you credit that mileage is a nice word. litres/100km is still a better unit than MPG, but mileage is a better term than fuel efficiency (or kilometreage).)
http://www.tug.org/docs/liang/
Here’s a javascript version: