kirby-typography icon indicating copy to clipboard operation
kirby-typography copied to clipboard

Kirby 3

Open tristantbg opened this issue 5 years ago • 7 comments

Do you plan to make a K3 version of this great plugin ? :)

tristantbg avatar Nov 13 '18 17:11 tristantbg

Yesss! But unfortunately, I dod not find the time for working on that so far. The PHP Typography library also made some great progress since the last release of Kirby-Typography, so a new release would be overdue anyway.

fabianmichael avatar Nov 20 '18 13:11 fabianmichael

@fabianmichael, what's the status of this plugin? Are there still plans for a Kirby 3 compatible version?

nilshoerrmann avatar Jun 03 '19 12:06 nilshoerrmann

@nilshoerrmann I am currently drowing in work and don’t know, when I can continue working on this plugin. I had big plans in the first place, like a panel view for customizing the plugin. As PHP Typography comes with a myriad of options, I always found it much nicer the way you can edit its settings in WordPress. But I will probably have to stick to the old way of configuring the plugin, even with a revamped version for Kirby 3.

In the meantime, I also found out the the most-used feature in my projects is hyphenation. I got a working prototype for a hyphenation plugin, please let me know if you are interested in that instead.

fabianmichael avatar Jun 03 '19 18:06 fabianmichael

Thanks for the offer. We are mostly interested in quote, apostrophe and dash handling – hyphenation has not been that important for us so far :)

nilshoerrmann avatar Jun 04 '19 09:06 nilshoerrmann

@nilshoerrmann In the meantime, I also found out the the most-used feature in my projects is hyphenation. I got a working prototype for a hyphenation plugin, please let me know if you are interested in that instead.

Hi @fabianmichael, if you could share with us the hyphenation plugin it would be much appreciated ! This is also what I used the most.

tristantbg avatar Jun 04 '19 15:06 tristantbg

@tristantbg I’ll try my best. Could take a few days though, as I have to investigate how to store settings for multilanguage-environments.

fabianmichael avatar Jun 04 '19 16:06 fabianmichael

I started a little experiment yesterday, if I can get the latest version of PHP Typography running in Kirby 3 and created a simple plugin that takes an array of settings per language and applies them in a field method called typography, e. g. $field->typography().

@fabianmichael: We never used Kirby 2 and thus we never used your plugin. We don't know how it works internally but our custom plugin does what we need for our projects. Now we don't want to get into your way and don't know how to proceed: we can just keep our plugin private, we can provide you with our plugin code, we can release it as a new plugin for K3. What do you think?

This is was the plugin does:

<?php

@include_once __DIR__ . '/vendor/autoload.php';

Kirby::plugin('hananils/typography', [
    'options' => [
        'settings' => [
            '*' => [
                'style_ampersands' => false,
                'style_caps' => false,
                'style_initial_quotes' => false,
                'style_numbers' => false,
                'style_hanging_punctuation' => false,
                'initial_quote_tags' => false
            ],
            'de' => [
                'smart_quotes_primary' => 'doubleLow9Reversed',
                'smart_quotes_secondary' => 'singleLow9Reversed',
                'smart_dashes_style' => 'international',
                'hyphenation_language' => 'de_DE',
                'diacritic_language' => 'de_DE'
            ],
            'fr' => [
                'smart_quotes_primary' => 'doubleGuillemetsFrench',
                'smart_quotes_secondary' => 'doubleCurled',
                'hyphenation_language' => 'fr_FR',
                'diacritic_language' => 'fr_FR'
            ]
        ]
    ],
    'fieldMethods' => [
        'typography' => function ($field) {
            $settings = new \PHP_Typography\Settings(true);
            $rules = kirby()->option('hananils.typography.settings');
            $language = kirby()->language()->code();

            // Get global settings
            $global = [];
            if (isset($rules['*']) && is_array($rules['*'])) {
                $global = $rules['*'];
            }

            // Get local settings
            $local = [];
            if (!empty($language) && isset($rules[$language]) && is_array($rules[$language])) {
                $local = $rules[$language];
            }

            // Apply settings
            $rules = array_merge($global, $local);
            foreach ($rules as $key => $value) {
                $setting = 'set_' . $key;
                if (method_exists($settings, $setting)) {
                    $settings->$setting($value);
                }
            }

            // Apply typographic styles
            $typographer = new \PHP_Typography\PHP_Typography();
            $field->value = $typographer->process($field->toString(), $settings);

            // Return field for chaning
            return $field;
        }
    ]
]);

nilshoerrmann avatar Jun 05 '19 10:06 nilshoerrmann