Jump to content

TextformatterRockSoftbreaks


bernhard
 Share

Recommended Posts

<?php

namespace ProcessWire;

class TextformatterRockSoftbreaks extends Textformatter
{
  public static function getModuleInfo()
  {
    return [
      'title' => 'RockSoftbreaks',
      'version' => '1.0.0',
      'summary' => 'Textformatter to replace strings by HTML softbreak',
    ];
  }

  public function format(&$str)
  {
    $str = str_replace("---", "&#8203;", $str);
    $str = str_replace("--", "&shy;", $str);
  }
}

There's always the problem of too large words on too small screens... In the past I often did a str_replace in my template file, but when using frontend editing that's no option because you need the original markup in the edited text and the replaced version in the presented markup. Textformatters do exactly that and that's why I build a textformatter for it. Feel free to change the replaced string to whatever you need ? 

Update: 3 dashes will insert a zero-width-space to make it possible to insert non-dash-softbreaks where dashes would be misleading (eg in mail addresses or in foo/bar which would otherwise result in foo/- bar)

pJo1pKF.gif

PS: If you have better solutions for that problem please let me know!

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Hi Bernhard, thanks for sharing!

2 hours ago, bernhard said:

PS: If you have better solutions for that problem please let me know!

Not a better solution but something that lessens the severity of the whole issue is built into Bootstrap 5: https://getbootstrap.com/docs/5.2/getting-started/rfs/ which is a separate project so not tied to bootstrap: https://github.com/twbs/rfs/tree/v9.0.6 

Using RFS means that there is less need for hyphenation but still there is, of course. Also, RFS makes it easier to adapt other values on the fly, if needed.

2 hours ago, bernhard said:

Update: 3 dashes will insert a zero-width-space to make it possible to insert non-dash-softbreaks

I have not yet installed the module (I will, when I have the time) but 3 dashes look odd to me. I would rather use only one character for that (underscore, maybe). So, if you could make it configurable that would be great, I think. (If it is not yet configurable, perhaps...)

Edited by szabesz
  • Like 2
Link to comment
Share on other sites

3 minutes ago, szabesz said:

Maybe the idea calls for a full fledged module?

That's one of the very rare cases where I thought a full module (github + modules directory) would be overkill ? 

8 minutes ago, szabesz said:

Not a better solution but something that lessens the severity of the whole issue is built into Bootstrap 5: https://getbootstrap.com/docs/5.2/getting-started/rfs/ which is a separate project so not tied to bootstrap: https://github.com/twbs/rfs/tree/v9.0.6 

Using RFS means that there is less need for hyphenation but still there is, of course. Also, RFS makes it easier to adapt other values on the fly, if needed.

Thx, very interesting! I'll start a topic in devtalk!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...