hananils / kirby-typographer

Kirby 3 plugin to apply micro typography
MIT License
37 stars 1 forks source link

Suggestion: add a zero-width-space after a dash to make dash-connected words breakable #16

Open animaux opened 6 months ago

animaux commented 6 months ago
// add a zero-width-space after a dash to make ~~dash~~slash-connected words breakable
'/\//uim' => '/​'
nilshoerrmann commented 6 months ago

Question: You are talking about slashes not dashes, right?

animaux commented 6 months ago

guitarist-guns-n-roses-musician-rocker-wallpaper-thumb-3881178841

Sorry, yes of course slashes!

animaux commented 6 months ago

BTW The zero-with space in the above code has zero with and is thus not visible :D

nilshoerrmann commented 6 months ago

This is how it's implemented right now in our internal dev version:

<?php

namespace Hananils\Corrections;

use Hananils\Correction;

class Slashes extends Correction
{
    public $replacements = [
        '/(\p{L})\/(\p{L})/uim' => '$1/&#8203;$2​'
    ];

    public function apply()
    {
        $this->inspector
            ->toTexts()
            ->filterBy('categories', 'excludes', ['preformatted'])
            ->replaceTextAll($this->replacements, isRegEx: true);
    }
}