<?php

/**
 * Get the hexa code of a color by its label.
 *
 * @param string $label
 *
 * @return string
 */
function color($label)
{
    $colors = [
        'music' => '#cccccc',
        'date' => '#E9F1FF',
        'info' => '#E9F1FF',
        'critical' => '#FF474A',
        'warning' => '#FF6836',
        'normal' => '#B3FF6C',
    ];

    return $colors[$label] ?? $colors['info'];
}

/**
 * Create emoji with padding.
 *
 * @param mixed $char
 */
function pemoji($char)
{
    return ' <span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span> ';
}

/**
 * Create emoji.
 *
 * @param mixed $char
 */
function emoji($char)
{
    return '<span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span>';
}

/**
 * Creates span with padding.
 *
 * @param string $text
 * @param string $foreground
 * @param string $background
 *
 * @return string
 */
function pspan($text, $foreground = null, $background = null)
{
    return span(sprintf(' %s ', $text), $foreground, $background);
}

/**
 * Creates span.
 *
 * @param string $text
 * @param string $foreground
 * @param string $background
 *
 * @return string
 */
function span($text, $foreground = null, $background = null)
{
    return sprintf(
        '<span background=\'%s\' foreground=\'%s\'>%s</span>',
        $background ?? '#333333',
        $foreground ?? color('normal'),
        $text
    );
}

/**
 * Returns a json of a block.
 *
 * @param string $name
 * @param array  $options
 *
 * @return string
 */
function block(string $name, array $options = [])
{
    $options = array_merge(
        [
            'full_text' => '',
            'align' => 'left',
            'name' => $name,
            'urgent' => false,
            'separator' => false,
            'separator_block_width' => 0,
        ],
        $options
    );

    return stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));
}
引用
<div%key%id="gist-5c879e5fa443e-f736069e32e25fe948d788198cfcae7de70506a5" class="gist-container"></div>
<script src="https://gist.deblan.org/cn/embedjs/5c879e5fa443e" async></script>