I use CSS hyphenation (hyphens:auto;
) for text paragraphs on websites. Sometimes it happens that email addresses are hyphenated resulting in a 'wrong' domain name. Example:
becomes
john.doe@planungs-
team.abc
How would I prevent that behavior? As this is user generated content, there is no way to manually add html elements. I was thinking about parsing texts with JavaScript, adding special tags to email addresses and use hyphens:none;
on those tags. But I'm worried about performance.
(I think this is an issue especially with German text, where there are a lot of compound nouns)
There is no way in CSS to refer to parts of text without making them elements (unless they can be referred to as pseudo-elements, like
:first-letter
, but there are just a few pseudo-elements currently in CSS, and they don’t help here).So you need to process the content programmatically, either server-side or client-side. Recognizing e-mail addresses is nontrivial, and you might consider handling some other constructs as well (e.g., URLs). For performance reasons, you might do this in client-side JavaScript so that the processing starts only after the document has loaded. Alternatively, if the data is saved on the server in HTML format, you could perform the processing before saving the data (though this increases the amount of data to be sent to browsers).