protected function format ($msg)
  {
    if (is_string ($msg)) {
      do {
        $msg = preg_replace_callback ('~
<\#(\w+)                            # capture LOG MARKUP TAG (ex: <#tag -> tag)
\s* (?: \| ([^>]+) )?               # capture optional tag arguments  (ex: <#tag|a|b|c> -> a|b|c)
>
(                                   # capture the tag\'s content
  (?:                               # begin loop
    (?= <\#\1 [ \s\|> ] )           # either the same tag is opened again (<#tag> <#tag| or <#tag(space))
    (?R)                            # and we must recurse
  |                                 # or
    .*?                             # capture everything
    (?= </\#\1> | <\#\1 [ \s\|> ] ) # until a closing/opening tag with the same name occurs
  )*                                # repeat loop
)                                   # end capture
</\#\1>                             # consume closing tag
~sx', function ($m) {
          list ($all, $tag, $args, $str) = $m;
          $args = $args ? explode ('|', $args) : [];
          switch ($tag) {
            case 'i':
              return "<div class='__log-item " . get ($args, 0) . "'>$str</div>";
            case 'row':
              return "<div class='__log-item __rowHeader " . get ($args, 0) . "'>$str</div>";
            case 'section':
              return "<div class='__log-section'>" . ($args ? "<div class='__log-title'>$args[0]</div>" : '') .
                     "$str</div>";
            case 'log':
              return "<div class='__log-stripe'>$str</div>";
            case 'data':
              return "<div class='__log-data'>$str</div>";
            case 'header':
              return "<div class='__header'>$str</div>";
            case 'footer':
              return "<div class='__footer'>$str</div>";
            case 'alert':
              return "<div class='__alert'>$str</div>";
            case 'type':
              $type = Debug::shortenType ($str);
              return "<span class='__type'>$type</span>";
            case 'indent':
              return "<div class='indent'>$str</div>";
            default:
              ob_clean ();
              throw new \RuntimeException("Invalid log tag <#$tag>");
          }
        }, $msg, -1, $count);
      } while ($count);
    }
    return $msg;
  }