如何防止换行符在所有浏览器的连字符 [英] How to prevent line break at hyphens on all browsers

查看:97
本文介绍了如何防止换行符在所有浏览器的连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在CMS上有一个ckeditor。我们的最终用户将通过该ckeditor输入一些长篇文章。我们需要一种方法来防止这些文章上的连字符断行。



是否还有防止所有浏览器上的连字符断行?


解决方案

恐怕没有更简单的方法比将文本拆分为单词(由空格分隔的非空格字符的序列)并将包含连字符的每个单词包含在 nobr 标记中。因此,输入数据如 bla bla foo-bar bla bla 将转为 bla bla< nobr> foo-bar< / nobr>



你甚至可以考虑插入 nobr 包含除字母和数字之外的任何内容。原因是一些浏览器甚至可能打破像2/3或f(0)的字符串(见我的页上浏览​​器中的换行符)。


We have a ckeditor on our CMS. Our end users will input some long articles via that ckeditor. We need a way to prevent line break at hyphens on those articles.

Is there anyway to prevent line break at hyphens on all browsers?

or does ckeditor have an option to prevent that?

解决方案

I’m afraid there’s no simpler way to do it reliably than splitting the text to "words" (sequences of non-whitespace characters separated by whitespace) and wrapping each "word" that contains a hyphen inside nobr markup. So input data like bla bla foo-bar bla bla would be turned to bla bla <nobr>foo-bar</nobr> bla bla.

You might even consider inserting nobr markup whenever the "word" contains anything but letters and digits. The reason is that some browsers may even break strings like "2/3" or "f(0)" (see my page on oddities of line breaking in browsers).

这篇关于如何防止换行符在所有浏览器的连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆