简体   繁体   中英

How to avoid line breaks inside `->` operator in `<code>` blocks?

I have a large HTML document containing C++ inline <code> sequences like foo->bar . Because hyphens are often used to induce line breaks, this sometimes results in output like:

blah blah foo-
>bar blah blah

which is undesirable.

  • Replacing the - (U+002D) with a (U+2011; non-breaking hyphen) isn't acceptable because it breaks searching for -> in common browsers.
  • Styling <code> elements with white-space:nowrap is undesirable because some inline code segments are long enough that they really should wrap.
  • Manually styling each -> operator with <span style="white-space:nowrap"> (or <nobr> ) is unacceptable because of the editorial burden, but it's possible to write a script to do this.

Is there a declarative way to specify that inside -> isn't a good place to break a line?

(This question is not actually a duplicate of How can I use CSS to preserve line breaks in an HTML <code> block? : this question asks how to avoid line breaks, while that question asks how to create them.)

No css declarative way by now. As far as I know there is no defined format for dictionaries to be used with hyphenate-resource (or @hyphenate-resource) or wide support for it, even using vendor specific dictionaries...

Use spans and script it as you pointed: but it's possible to write a script to do this

It's not a perfect solution, but it satisfies all your criteria and it is crossbrowser

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM