nunomaduro / termwind

🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
MIT License
2.29k stars 78 forks source link

[Feature] Ability to extend HTML renderer #83

Closed butschster closed 2 years ago

butschster commented 3 years ago

There is only one way to increase amount of elements in termwind - Add PRs with new features.

But sometimes requires an ability to extend HtmlRenderer for specific project.

Something like this

HtmlRenderer::extend('code', static function(\DOMNode $node): Raw {
    $highlighter = new Highlighter();

    $line = (int) $node->getAttribute('line');

    $html = array_reduce(
        iterator_to_array($node->childNodes),
        static fn(string $html, \DOMNode $child) => $html .= $child->ownerDocument->saveXML($child),
        ''
    );

    $html = html_entity_decode($html);

    return Termwind::raw(
        $highlighter->highlight(html_entity_decode($html), $line)
    );
});

As you understood, this package fits me on 100%. I have a pet project where one of the features is rendering debug output into a terminal and I have a lot of legacy code I'm trying to move to this package.

nunomaduro commented 2 years ago

No plans for this.