jmcnevin / rubypants

RubyPants: SmartyPants for Ruby
Other
29 stars 20 forks source link

Precede dashes by a non-breaking space (or thinspace) #7

Closed vermiculus closed 7 years ago

vermiculus commented 8 years ago

Lines in a paragraph should never start with a dash – use a non-breaking space or a thinspace to remove that possibility.

Likely fix at https://github.com/jmcnevin/rubypants/blob/b2736f5d62df5c69dc9e77477ed4d9b472107227/lib/rubypants/core.rb#L329

agriffis commented 8 years ago

Could you elaborate on the problem? Also that link points into the stupefy_entities function, is that what you intended?

vermiculus commented 8 years ago

Ah, nope – sorry: correct link

Here's a 'bad' paragraph:

This is just some filler text. It doesn't say much, but it doesn't need to: its sole purpose is to get – to begin a new line.

And here's a 'good' paragraph:

This is just some filler text. It doesn't say much, but it doesn't need to: its sole purpose is to get – to begin a new line – a plan thwarted by  .

It's just a rule of typography; here's a reference.

agriffis commented 8 years ago

@vermiculus That link seems to go to "def default_entities" ... is that what you intended? I'm not seeing the connection between that and "likely fix"

Regarding "bad" paragraph and "good" paragraph, here's what shows in my browser. I think this is also not what you intended:

screenshot from 2016-08-22 19-52-23

I think this is the paragraph you meant from the reference. Pasting here for safekeeping:

When a dash falls between the end of one line and the beginning of the next, you should try to ensure that the dash is placed at the end of the first line and not at the beginning of the second, if you can.

I agree it would be nice to fix this. Do you want to provide a PR?

vermiculus commented 8 years ago

Hm, this is what shows on my browser:

screen shot 2016-08-22 at 10 28 30 pm

Anyway, I'll work on providing a PR.

vermiculus commented 8 years ago

The idea is to replace every recognized ASCII endash with a thinspace+endash – would that not be in default_entities? (I'll freely admit I don't know Ruby beyond hello, world.)

agriffis commented 8 years ago

Unfortunately in my own testing it appears that Chrome and Firefox both will also split lines between word and dash, for example hi—just saying—this is an example might be rendered with —just or —this starting a line. However both browsers seem to change their behavior if the character prior to the dash is a non-breaking space, either   or  (zero-width non-breaking space)

So the fuller fix, ignoring the various modes, should be something like:

  1. foo -- bar becomes foo&nbsp— bar
  2. foo--bar becomes foo—bar

This goes beyond modifying default_entities and should likely be configurable in options.

agriffis commented 7 years ago

@vermiculus released v0.5.1 which should fix this for you. Let me know!