diff --git a/src/ValueObjects/Styles.php b/src/ValueObjects/Styles.php index 3ed976e..617ed56 100644 --- a/src/ValueObjects/Styles.php +++ b/src/ValueObjects/Styles.php @@ -416,6 +416,15 @@ final public function truncate(int $limit = 0, string $end = '…'): self { $this->textModifiers[__METHOD__] = function ($text, $styles) use ($limit, $end): string { $width = $styles['width'] ?? 0; + + if (is_string($width)) { + $width = self::calcWidthFromFraction( + $width, + $styles, + $this->properties['parentStyles'] ?? [] + ); + } + [, $paddingRight, , $paddingLeft] = $this->getPaddings(); $width -= $paddingRight + $paddingLeft; diff --git a/tests/classes.php b/tests/classes.php index ac7b07b..05aa9b5 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -186,6 +186,28 @@ expect($html)->toBe(' te… '); }); +test('truncate with w-full', function () { + putenv('COLUMNS=5'); + + $html = parse(<<<'HTML' + texttext + HTML); + + expect($html)->toBe('text…'); +}); + +test('truncate with w-division', function () { + putenv('COLUMNS=6'); + + $html = parse(<<<'HTML' +