Skip to content

Kirby 4.1.2

smartypants

Convert typical text formatting issues into a typographically correct version

Enable SmartyPants

When you activate SmartyPants in your config, SmartyPants rules are automatically applied whenever you use the ->kirbytext() or ->smartypants() field methods.

To enable SmartyPants, you can set the smartypants option to true:

/site/config/config.php
return [
    'smartypants' => true
];

Custom replacements

You can also override each of the default replacements:

/site/config/config.php
return [
    'smartypants' => [
        'doublequote.open'  => '“',
        'doublequote.close' => '”',
        //…
    ]
];

Here is a list of all default settings:

return [
    'smartypants' => [
        'attr'                       => 1,
        'doublequote.open'           => '“',
        'doublequote.close'          => '”',
        'doublequote.low'            => '„',
        'singlequote.open'           => '‘',
        'singlequote.close'          => '’',
        'backtick.doublequote.open'  => '“',
        'backtick.doublequote.close' => '”',
        'backtick.singlequote.open'  => '‘',
        'backtick.singlequote.close' => '’',
        'emdash'                     => '—',
        'endash'                     => '–',
        'ellipsis'                   => '…',
        'space'                      => '(?: | | |&#0*160;|&#x0*[aA]0;)',
        'space.emdash'               => ' ',
        'space.endash'               => ' ',
        'space.colon'                => ' ',
        'space.semicolon'            => ' ',
        'space.marks'                => ' ',
        'space.frenchquote'          => ' ',
        'space.thousand'             => ' ',
        'space.unit'                 => ' ',
        'guillemet.leftpointing'     => '«',
        'guillemet.rightpointing'    => '»',
        'geresh'                     => '׳',
        'gershayim'                  => '״',
        'skip'                       => 'pre|code|kbd|script|style|math',
    ]
];

Language specific replacements

To use language specific replacements, you have to enable the smartypants option in your config and then add your array of options to each language file in /site/languages/.

/site/config/config.php
return [
    'smartypants' => true
];
/site/languages/en.php
<?php

return [
    'code' => 'en',
    'default' => true,
    'direction' => 'ltr',
    'locale' => 'en_US',
    'name' => 'English',
    'translations' => [],
    'url' => null,
    'smartypants' => [
        'doublequote.open'  => '&#8220;',
        'doublequote.close' => '&#8221;',
        //…
    ]
];