Display * (asterisk) in textfield and disable italic function

Since the * is used in german writing to highlight other genders, I would like to make it appear in my textfields and not use it as italic tag. How is that possible?

You can use a backslash escape \*.


Hey, thanks for the quick reply. Thats a good option, but in my case it would not be so handy, because its quite much text and many editors that all have to search an replace in their texts before filling it into the panel.

You could use a pre filter that auto-replaces all asterisks with a backslash escape before markdown is applied (that doesn’t make any changes in your texts, it just does it at runtime).

See https://getkirby.com/docs/developer-guide/kirbytext/filters, section pre & post filters.

I ran into the same problem and I solved it with a kirbytext:before hook to add a \ in front of the gender-*.
Add this to the hooks section in config.php

    'kirbytext:before' => function ($text) {
            $pattern = '/(\w)(\*)(\w)/m';
            $replacement = '$1\\\$2$3';
            $text = preg_replace($pattern, $replacement, $text);
            return $text;

The regex pattern has to make sure it matches only single asterisks within words.
The replacement has to replace all submatches: $1 and $3 refer to the characters before and after the asterisk, 2 is the asterisk preceded by a backslash that has to be escaped twice (if escaped only once it escapes the sign of $2)

This allows the users to still safely use asterisks for italics.

For reference to the kirbytext:before hook:


Tank you! …your solution helped me a lot, I also found this pen to enhance this for screenreader: https://codepen.io/gunnarbittersmann/pen/Rdwzdo

so I tried to adapt it the following way:

'kirbytext:before' => function ($text) {
  $pattern = array ('/\b\*innen\b/',
  $replacement = array ("<span class='genderstar' aria-hidden='true'>\*</span><span aria-hidden='true'>innen</span><span visually-hidden='true'>Innen</span>", "<span class='genderstar' aria-hidden='true'>\*</span><span aria-hidden='true'>in</span><span visually-hidden='true'>In</span>");
  $text = preg_replace($pattern, $replacement, $text);
  return $text;

…I just don’t have a confident feeling about my regex abilities :smiley: so I was wondering if there is a cleaner way?

…in addition it would be great to bind this to one language only in case of multilanguage sites, any ideas how to do that?

Just stumbled upon this problem with a writer field. As this field ist WYSIWYG and the text is generated and saved as HTML code as I write, the workarounds with kirbytext hooks or backslash escape don’t apply here. Any suggestions for this, apart from disabling italic markup?