5

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.)

Community
  • 1
  • 1
Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39
  • is searching for `->` really serious? I've never searched for such a thing, just keywords only. – King King Jun 07 '14 at 20:35
  • 3
    There doesn't seem to be a solution that satisfies all your criteria. See http://stackoverflow.com/questions/7691569/no-line-break-after-a-hyphen – Barmar Jun 07 '14 at 20:40
  • 1
    @King King: I've several times had to search my own code for `foo->bar`. I don't think he's only referring to searching for the `->` operator alone. – BoltClock Jun 08 '14 at 15:51

1 Answers1

1

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

miguel-svq
  • 2,136
  • 9
  • 11
  • Kinda sucks, but it's good to get some confirmation that I'm not missing anything. – Jeffrey Yasskin Jun 08 '14 at 20:26
  • Yes, I know. :D The worst is that it was removed (http://www.w3.org/TR/2011/WD-css3-text-20110412/ vs http://www.w3.org/TR/2011/WD-css3-text-20110901) and the other hyphenate-... properties that could give some kind of option was deferred to level 4 (http://www.w3.org/TR/2012/WD-css3-text-20120119/) – miguel-svq Jun 08 '14 at 21:28