bernhard Posted October 4, 2022 Share Posted October 4, 2022 <?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("---", "​", $str); $str = str_replace("--", "­", $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) PS: If you have better solutions for that problem please let me know! 2 1 Link to comment Share on other sites More sharing options...
szabesz Posted October 4, 2022 Share Posted October 4, 2022 (edited) 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 October 4, 2022 by szabesz 2 Link to comment Share on other sites More sharing options...
szabesz Posted October 4, 2022 Share Posted October 4, 2022 @bernhardSorry for watching but not seeing :) since you just posted the module in the post above, there is no room for configuration, I see. Maybe the idea calls for a full-fledged module? Link to comment Share on other sites More sharing options...
bernhard Posted October 4, 2022 Author Share Posted October 4, 2022 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! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now