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

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

问题描述

我们的 CMS.我们的最终用户将通过该 CKEditor 输入一些长文章.我们需要一种方法来防止这些文章的连字符处出现换行符.

We have the CKEditor in 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 a way to prevent line break at hyphens in all browsers?

或者 CKEditor 是否可以选择防止这种情况发生?

Or does CKEditor have an option to prevent that?

推荐答案

恐怕没有比将文本拆分为单词"(由空格分隔的非空格字符序列)并换行更可靠的方法了nobr 标记中包含连字符的每个单词".因此,像 bla bla foo-bar bla bla 这样的输入数据将被转换为 bla bla foo-bar</nobr>bla bla.

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.

您甚至可以考虑在单词"包含字母和数字以外的任何内容时插入 nobr 标记.原因是一些浏览器甚至可能会破坏像2/3"或f(0)"这样的字符串(参见我的页面 浏览器中的换行异常).

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天全站免登陆