diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index fc2b64bf156bb..fb6766ca13bfb 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Deprecate not declaring the parameter type in callable commands defined through `setCode` method * Add support for help definition via `AsCommand` attribute * Deprecate methods `Command::getDefaultName()` and `Command::getDefaultDescription()` in favor of the `#[AsCommand]` attribute + * Add support for Markdown format in `Table` 7.2 --- diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 9ff73d2cc371a..2811d58d4a01a 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -417,7 +417,7 @@ public function render(): void continue; } - if ($isHeader && !$isHeaderSeparatorRendered) { + if ($isHeader && !$isHeaderSeparatorRendered && $this->style->displayOutsideBorder()) { $this->renderRowSeparator( self::SEPARATOR_TOP, $hasTitle ? $this->headerTitle : null, @@ -449,7 +449,10 @@ public function render(): void } } } - $this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat()); + + if ($this->getStyle()->displayOutsideBorder()) { + $this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat()); + } $this->cleanup(); $this->rendered = true; @@ -868,6 +871,12 @@ private function cleanup(): void */ private static function initStyles(): array { + $markdown = new TableStyle(); + $markdown + ->setDefaultCrossingChar('|') + ->setDisplayOutsideBorder(false) + ; + $borderless = new TableStyle(); $borderless ->setHorizontalBorderChars('=') @@ -905,6 +914,7 @@ private static function initStyles(): array return [ 'default' => new TableStyle(), + 'markdown' => $markdown, 'borderless' => $borderless, 'compact' => $compact, 'symfony-style-guide' => $styleGuide, diff --git a/src/Symfony/Component/Console/Helper/TableStyle.php b/src/Symfony/Component/Console/Helper/TableStyle.php index be956c109edf5..74ac589256834 100644 --- a/src/Symfony/Component/Console/Helper/TableStyle.php +++ b/src/Symfony/Component/Console/Helper/TableStyle.php @@ -46,6 +46,7 @@ class TableStyle private string $cellRowFormat = '%s'; private string $cellRowContentFormat = ' %s '; private string $borderFormat = '%s'; + private bool $displayOutsideBorder = true; private int $padType = \STR_PAD_RIGHT; /** @@ -359,4 +360,16 @@ public function setFooterTitleFormat(string $format): static return $this; } + + public function setDisplayOutsideBorder($displayOutSideBorder): static + { + $this->displayOutsideBorder = $displayOutSideBorder; + + return $this; + } + + public function displayOutsideBorder(): bool + { + return $this->displayOutsideBorder; + } } diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 646c6baca8de1..a50ede664f8ee 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -112,6 +112,20 @@ public static function renderProvider() | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------------------------+------------------+ +TABLE, + ], + [ + ['ISBN', 'Title', 'Author'], + $books, + 'markdown', + <<<'TABLE' +| ISBN | Title | Author | +|---------------|--------------------------|------------------| +| 99921-58-10-7 | Divine Comedy | Dante Alighieri | +| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | +| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | +| 80-902734-1-6 | And Then There Were None | Agatha Christie | + TABLE, ], [