Panel outputs additional line breaks between fields. Can this be overridden?

When creating content, I tend to use the following formatting:

title: Title of page
----
excerpt: This is a page of dummy content
----
text: Hello there! This text is just a placeholder!

However, if I’m to edit this using the panel, the file is updated to use styling as follows:

title: Title of page

----

excerpt: This is a page of dummy content

----

text: Hello there! This text is just a placeholder!

It seems this is due to the following (on line 117 in kirby/toolkit/lib/data.php):

return implode("\n\n----\n\n", $result);

I’ve overridden this with the following:

return implode("\n----\n", $result);

but that can only be a short-term solution. Is there any reason why additional line breaks are used? Can there be (or is there) a way to override this behaviour?

Best,

Paul

Yes. You can overwrite the whole encoding function from your config.php:

data::$adapters['kd']['encode'] = function($data) {

  $result = array();
  foreach($data AS $key => $value) {
    $key = str::ucfirst(str::slug($key));

    if(empty($key) || is_null($value)) continue;

    // avoid problems with arrays
    if(is_array($value)) {
      $value = '';
    }

    // escape accidental dividers within a field
    $value = preg_replace('!\n----(.*?\R*)!', "\n ----$1", $value);

    // multi-line content
    if(preg_match('!\R!', $value, $matches)) {
      $result[$key] = $key . ": \n\n" . trim($value);
    // single-line content
    } else {
      $result[$key] = $key . ': ' . trim($value);        
    }

  }
  return implode("\n----\n", $result);

};

Fantastic, that’ll work. At least this way my changes won’t be overridden when I update any submodules. Cheers!