Smartypants parser not working

Hi,

I’m porting a site from v2 to v3 and the Smartypants parser seems not working.
I’ve enable the option in site/config/config.php like this:

return [
    'debug' => true,
    'languages' => true,
    'smartypants' => true,
];

but I can’t get the text to parse correctly with kirbytext() and get a Type Error if I use smartypants() directly on a text field:

TypeError thrown with message “Argument 3 passed to Kirby\Cms\App::{closure}() must be of the type array, boolean given, called in /Users/lorenzoascani/Sites/fds_v5/kirby/src/Cms/App.php on line 1094”

Has anyone noticed the same behaviour?

‘smartypants’ => true,

The error says that you have to pass an array here, not just true or false. Since these are the defaults

 public function defaults(): array
    {
        return [
            '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',
        ];
    }

You can replace these defaults in your options.

Thank you.

I referred to this doc: https://getkirby.com/docs/guide/content/text-formatting#smartypants, which is the same I used in v2

I tried to put the array with the options you listed in my config file but it didn’t work.
Am I missing something?

Hm, what is your Kirby version?

This works for me, at least that’s what I would expect to happen

    'smartypants' => [
        'doublequote.open'           => '—', //replace double quote with mdash for testing
    ]

In my content file:

Text: Some stupid "text"

In template:

<?= $page->text()->smartypants() ?>

Opening quote becomes mdash, rendered as Some stupid —text"

Ok, so if I put an array (even if empty) in the config file it works:

'smartypants' => [],

Thank you for help, I knew I was messing something simple :slight_smile: but maybe the docs should be updated?

Definitely

Unfortunately I tested only with a simple field with only quotes and dashes: If I try to mix other markdown functionality (bold, links, etc.) it won’t parse using smartypants(), while kirbytext() still fails to parse the correct quotes.

Perhaps there is a bug still. I’m currently using v3.1.1.

You can use both:

<?= $page->text()->kirbytext()->smartypants() ?>

I don’t think you have to activate the option at all in your config. You only have to set the option if you want to override the defaults.

Ok now I see and it works. Thanks again!

I previously thought that it would work like in v2 (and as described in the docs)

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

I’ll try to get some more information tomorrow and will then fix the docs accordingly.

thank you, it’ll be cool if smartypants is automatically applied on ->kirbytext() like in V2 and also in ->kirbytextinline()

I’ve created a bug report:

This is now fixed in 3.1.4

I have a related topic. For some reason, instead of an em-dash (“—”), three hyphens --- are returned by smartypants as an en-dash followed by a hyphen like so (“—-”)

Does this happen to others? Is there a solution?