Smartypants parser not working

#1

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?

0 Likes

#2

‘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.

0 Likes

#3

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?

0 Likes

#4

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"

0 Likes

#5

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?

0 Likes

#6

Definitely

0 Likes

#7

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.

0 Likes

#8

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.

0 Likes

#9

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.

0 Likes

#10

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

0 Likes

Set smartypants options in config.php
#11

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

0 Likes

#12

I’ve created a bug report:

0 Likes