Version 3.2.0

Enhanced HTML/XML parser.

Table of Contents
  1. Extensions
    1. Layout

This release drops the use of regular expressions from the HTML and XML parser. This should improve the performance of the DOM tokenization process. Don’t worry, it still does not require the PHP dom extension as a dependency. Two new core functions, apart() and pair(), have been added. They can be used to parse partial HTML/XML string into a series of tokens.

Converting smiley patterns to emoticons will be easier and much faster in the future with the help of this function:

Hook::set('page.content', function ($content) {
    if ("" === ($content ?? "")) {
        return $content;
    }
    $r = "";
    foreach (apart($content, ['code', 'kbd', 'script', 'style', 'textarea']) as $v) {
        // Apply the smiley conversion only to plain text tokens!
        if (0 === $v[1]) {
            $r .= strtr($v[0], [':)' => '☺']);
            continue;
        }
        $r .= $v[0];
    }
    return $r;
});

There will be many more tasks that can be easily solved with this feature without any regular expressions involved, such as surrounding text nodes with a <mark>…</mark> element, safely converting embed URL into HTML code, etc.

Extensions

Layout

The layout() helper function has been added just for convenience. This may not be very handy in general, since layout developers are already used to the self::name() syntax to access a layout part:

<?= layout('enter'); ?>
<main>
  <!-- Content goes here… -->
</main>
<?= layout('exit'); ?>

2 Comments

Akbar

untuk penulisan fungsi layout ini hanya berlaku untuk layout('enter') dan layout('exit') ini aja kang? atau berlaku untuk fungsi lain yg biasa menggunakan self::name() ini kang?