Prevent Kirby from trimming whitespace

Hello,

I would like to use nested list with markdown editor like so:

- List item lvl 1
- List item lvl 1
- List item lvl 1
  - List item lvl 2
  - List item lvl 2
    - List item lvl 3
    - List item lvl 3
- List item lvl 1
- List item lvl 1

Problem is that when I try to save such structure with Kirby all the leading space get removed so markdown recognises only first level of the list.

Any tips how to deal with this?

Thanks a lot!

Hm, works for me. What is your Kirby version?

My Kirby version is 2.5.5.

But when you try to save the example you posted, all the spaces will be preserved and visible on front-end? Because in my case whenever I save some textarea field all the trailing spaces get removed.

Yes, of course I tested with saving the page…:wink: Kirby 2.5.8

Hi,

I’m having this issue with textareas inside of structure fields.
For regular textareas nested lists work fine, but inside of structure fields, the whitespace gets stripped out after saving the page.
Can you reproduce this?
Any other ideas on how to create a nested list in a textarea inside a structure field?

Georg

Hi George,

this is happening because structure is saving data as YAML and indentation and white-spaces play key role in YAML.

You can also checkout these: https://github.com/getkirby/panel/issues/714 and Prevent Panel from stripping spaces for further information.

Oleg

In older versions of Kirby nested lists within textareas of structure fields were possible, just trying to find out when it stopped working. But since the above mentioned issue is very old, that must have been quite some while ago…

If you absolutely must have nested list, I recommend you use subpages instead of a structure field.

Oh, too bad.
I can’t switch to subpages here, in this case our content model prevents us from this as we need to use a structure field. We also need to have nested lists in it …
I will do some research on this, maybe I find some HTML input that works.
Thank you!

As a workaround I created now a Kirbytext filter:

kirbytext::$pre[] = function($kirbytext, $value) {
  return str_replace('__-', '  -', $value);
};

This assumes that the editor is entering __- in the structure field textarea for nested lists.