public static function highlightLine(string $html, int $line, int $lines = 15): string
    {
        $source = \explode("\n", "\n" . \str_replace("\r\n", "\n", $html));
        $out = '';
        $spans = 1;
        $start = $i = \max(1, \min($line, \count($source) - 1) - (int)\floor($lines * 2 / 3));
        while (--$i >= 1) { // find last highlighted block
            if (\preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
                if ($m[1] !== '</span>') {
                    $spans++;
                    $out .= $m[1];
                }
                break;
            }
        }

        $source = \array_slice($source, $start, $lines, true);
        \end($source);
        $numWidth = \strlen((string)\key($source));

        foreach ($source as $n => $s) {
            $spans += \substr_count($s, '<span') - \substr_count($s, '</span');
            $s = \str_replace(["\r", "\n"], ['', ''], $s);
            \preg_match_all('#<[^>]+>#', $s, $tags);
            if ($n == $line) {
                $out .= \sprintf(
                    "<span class=\"highlight\">%{$numWidth}s:    %s\n</span>%s",
                    $n,
                    \strip_tags($s),
                    \implode('', $tags[0])
                );
            } else {
                $out .= \sprintf("<span class=\"line\">%{$numWidth}s:</span>    %s\n", $n, $s);
            }
        }
        $out .= \str_repeat('</span>', $spans) . '</code>';

        return $out;
    }