xles / hyphenator

Automatically exported from code.google.com/p/hyphenator
GNU General Public License v3.0
0 stars 0 forks source link

Setting 'urlhyphencar' to 'soft hyphen' #198

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I am trying to hyphenate the following URL:

    <a class="share-source separator hyphenate" href="http://www.aplitrak.com/?adid=b2plbm5pbmdzLjY1NDM1LjU0MDNAbmluZXNoYXJwLmFwbGl0cmFrLmNvbQ
    </a>

2. The first time I execute Hyphenator.run(), zero-width-space characters are 
added to the URL, as shown below:
    http://&#8203;www.&#8203;aplitrak.&#8203;com/?&#8203;adid=b2plbm5pbmdzLjY1NDM1LjU0MDNAbmluZXNoYXJwLmFwbGl0cmFrLmNvbQ

    However, the browser does not wrap correctly, and the layout for my page is still broken.

3. If I re-execute Hyphenator.run(), the zero-width-space characters are 
removed, and instead soft hyphens are added to the URL, as shown below:

    http://​www.​apli&shy;trak.​com/?​adid=b2&shy;plb&shy;m5pb&shy;md&shy;zLjY1ND&shy;M1LjU0MDNAbm&shy;luZXNoYXJwLm&shy;Fw&shy;bGl0cm&shy;FrLm&shy;N&shy;vbQ

    With these soft hyphens, wrapping is correct and working as expected.

What is the expected output? What do you see instead?
In order to get the expected output, I have to execute Hyphenator.run() twice. 
I think setting urlhyphenchar property to a soft hyphen might fix the problem, 
but I have been unable to do this. I have tried both Hyphenator.config({ 
urlhyphenchar: '&#173;' }) and Hyphenator.config({ urlhyphenchar: '&shy;' }), 
but the HTML characters are not decoded.

Is it possible to set urlhyphenchar to a soft-hyphen (or other HMTL-encoded 
characters)?
Is there any other way I could fix the problem, without having to execute 
Hyphenator.run() twice?

What version of the product are you using? On what operating system?
I am using Hyphenator.js Version 4.2.0 on Windows 8 (Chrome Version 
34.0.1847.116 m).

Original issue reported on code.google.com by Gauci.Ra...@gmail.com on 28 Apr 2014 at 9:42

GoogleCodeExporter commented 9 years ago
Hi

Thanks for this report. It uncovers several bugs at once!

First, lets see what actually happens:
Hyphenator.js splits text into words and checks if a word is a normal word or 
of url-style (also e-mail adresses).
Normal words are hyphenated using the hyhenchar (defaults to ­)
URL-styled 'words' should not be hyphenated with softhyphens (otherwise 
www.aplitrak.com would in a bad case become www.apli-trak.com). So 
Hyphenator.js inserts by default a zero width space after some special 
characters (these are: /.?#&_,:;!@).

--> In your case the first part of the URL is handled properly but the query 
string is not. I'll try to fix this.

When Hyphenator.run() is called a second time, Hyphenator.js doesn't recognise 
the url (it now contains zero width spaces) so it is treated as a normal word 
and thus gets hyphenated by inserting '­' (Allthough the zero width spaces are 
not replaced in my tests).
This behaviour is expected, so no changes are necessary here.
--> Hyphenator.run() should not be called more than once. Hyphenator.js writes 
a warning about that to the console but I'll have to document that…

The last bug: html-entities are not decoded/encoded (whatever), when they are 
set in Hyphenator.config() 'hyphenchar' and 'urlhyphenchar'.
This can be accomplished by using String.fromCharCode():

Hyphenator.config({
    urlhyphenchar: String.fromCharCode(173) //zero width space
});

But as noted above, URLs should not be hyphenated with soft hyphens.
--> This needs documentation.

Again thanks for reporting (it's a long way to perfection).
Mathias

Original comment by mathiasn...@gmail.com on 2 May 2014 at 10:40

GoogleCodeExporter commented 9 years ago
Thank you very much for noting the bugs and explaining the functionality in 
detail.

Kindly keep me updated if any relevant fixes are released.

Thanks again,
Rachel.

Original comment by Gauci.Ra...@gmail.com on 6 May 2014 at 6:53

GoogleCodeExporter commented 9 years ago
All fixed in the trunk and going in the next release

Original comment by mathiasn...@gmail.com on 17 Oct 2014 at 8:28