8000 [Console] Add markdown format to Table · symfony/symfony@034b574 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 034b574

Browse files
committed
[Console] Add markdown format to Table
1 parent 6f4f04b commit 034b574

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Deprecate not declaring the parameter type in callable commands defined through `setCode` method
99
* Add support for help definition via `AsCommand` attribute
1010
* Deprecate methods `Command::getDefaultName()` and `Command::getDefaultDescription()` in favor of the `#[AsCommand]` attribute
11+
* Add support for Markdown format in `Table`
1112

1213
7.2
1314
---

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public function render(): void
417417
continue;
418418
}
419419

420-
if ($isHeader && !$isHeaderSeparatorRendered) {
420+
if ($isHeader && !$isHeaderSeparatorRendered && $this->style->displayOutsideBorder()) {
421421
$this->renderRowSeparator(
422422
self::SEPARATOR_TOP,
423423
$hasTitle ? $this->headerTitle : null,
@@ -449,7 +449,10 @@ public function render(): void
449449
}
450450
}
451451
}
452-
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
452+
453+
if ($this->getStyle()->displayOutsideBorder()) {
454+
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
455+
}
453456

454457
$this->cleanup();
455458
$this->rendered = true;
@@ -868,6 +871,12 @@ private function cleanup(): void
868871
*/
869872
private static function initStyles(): array
870873
{
874+
$markdown = new TableStyle();
875+
$markdown
876+
->setDefaultCrossingChar('|')
877+
->setDisplayOutsideBorder(false)
878+
;
879+
871880
$borderless = new TableStyle();
872881
$borderless
873882
->setHorizontalBorderChars('=')
@@ -905,6 +914,7 @@ private static function initStyles(): array
905914

906915
return [
907916
'default' => new TableStyle(),
917+
'markdown' => $markdown,
908918
'borderless' => $borderless,
909919
'compact' => $compact,
910920
'symfony-style-guide' => $styleGuide,

src/Symfony/Component/Console/Helper/TableStyle.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class TableStyle
4646
private string $cellRowFormat = '%s';
4747
private string $cellRowContentFormat = ' %s ';
4848
private string $borderFormat = '%s';
49+
private bool $displayOutsideBorder = true;
4950
private int $padType = \STR_PAD_RIGHT;
5051

5152
/**
@@ -359,4 +360,16 @@ public function setFooterTitleFormat(string $format): static
359360

360361
return $this;
361362
}
363+
364+
public function setDisplayOutsideBorder($displayOutSideBorder): static
365+
{
366+
$this->displayOutsideBorder = $displayOutSideBorder;
367+
368+
return $this;
369+
}
370+
371+
public function displayOutsideBorder(): bool
372+
{
373+
return $this->displayOutsideBorder;
374+
}
362375
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ public static function renderProvider()
112112
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
113113
+---------------+--------------------------+------------------+
114114

115+
TABLE,
116+
],
117+
[
118+
['ISBN', 'Title', 'Author'],
119+
$books,
120+
'markdown',
121+
<<<'TABLE'
122+
| ISBN | Title | Author |
123+
|---------------|--------------------------|------------------|
124+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
125+
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
126+
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
127+
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
128+
115129
TABLE,
116130
],
117131
[

0 commit comments

Comments
 (0)
0