Paragraph alignement

I’ve actually done this some time ago site/plugins/center/center.php

<?php

/**
 * Center Plugin
 *
 * @author Jimmy Rittenborg <jimmy@sitemarina.com>
 * @version 1.0.0
 */

kirbytext::$pre[] = function($kirbytext, $text) {

  $text = preg_replace_callback('!\(center(…|\.{3})\)(.*?)\((…|\.{3})center\)!is', function($matches) use($kirbytext) {

    $html = kirbytext($matches[2]);

    return '<div class="' . c::get('center.class', 'text-center') . '">' . $html . '</div>';

  }, $text);

  return $text;

};

Implying that your assets/css/styles.css already has a

.text-center {
  text-align: center;
}

You can then do

(center...)
Center all the texts.
(link: http://example.com link: I'm a centered link)
(...center)

and if you want to change the css class for the center container site/config/config.php

c::set('center.class', 'text--centered');
3 Likes