World is now on Opti ID! Learn more
World is now on Opti ID! Learn more
We usually handle this by instructing the editors to add three dashes where there's a possible line break.
E.g.
Allokerings---strategi---sammanslutnings---förbundet
public static string ReplaceDashesWithShy(this string text) {
return string.IsNullOrEmpty(text) ? text : text.Replace("---", "­");
}
Add a shared displaytemplate in ~/Views/Shared/DisplayTemplates/String.cstml
@{
var str = Model as string;
}
@if(str != null) {
@( WebUtility.HtmlDecode(str.ReplaceDashesWithShy()) )
} else {
@Html.DisplayFor(model => model)
}
That will handle any strings with ---. Or are you looking for some solution for xhtmlstrings as well?
Regarding the automatic version of this you must use an external library, I've never used a c# version of this but found the Hyphenator.Net library
E.g
using Hyphenator;
var hyphenator = new Hyphenator.Hyphenator("sv"); // "sv" for Swedish
string result = hyphenator.HyphenateText("avstavning");
Console.WriteLine(result); // Outputs: av-stav-ning
I have used the Pyphen library in python and know that that works pretty well
import pyphen
dic = pyphen.Pyphen(lang='sv_SE')
print(dic.inserted('avstavning')) # => av·stav·ning
If the Hyphenator.Net library doesn't work you can always wrap Pyphen in a container or so and call it during the publish event and parse your HTML that way.
Found it! The editor had made copy/paste from the browser and you the get the soft hyphen included. Then when publishing the page it goes down to the database. So it was an editor issue.
Hi!
We have a block with a regular property:
If I have a really long title for example the made up word Allokeringsstrategisammanslutningsförbundet I think Optimizely automatic adds a soft hyphen.
The word is rendered like this: Allokeringsstrategi­sammanslutningsförbundet
Is it Optimizely doing this or is there something else? If I debug the code the value coming back before rendering contains a soft hyphen.
Thanks!
/Kristoffer