Generate tables in a markdown compatible format
tomzx opened this issue · comments
Since I will be analyzing the issues that should be fixed to make php-semver-checker
more useful and correct, I plan on writing down in case analysis issues what the incorrectly suggested changes are.
The current table format does not display well at all in markdown.
Compare
+-------+----------------------------------------------------------+-------------------------------------------------------+---------------------------------+------+
| Level | Location | Target | Reason | Code |
+-------+----------------------------------------------------------+-------------------------------------------------------+---------------------------------+------+
| MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:334 | Symfony\Component\Console\Style\SymfonyStyle::writeln | [public] Method has been added. | V015 |
| MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:343 | Symfony\Component\Console\Style\SymfonyStyle::write | [public] Method has been added. | V015 |
| MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:352 | Symfony\Component\Console\Style\SymfonyStyle::newLine | [public] Method has been added. | V015 |
+-------+----------------------------------------------------------+-------------------------------------------------------+---------------------------------+------+
to
Level | Location | Target | Reason | Code |
---|---|---|---|---|
MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:334 | Symfony\Component\Console\Style\SymfonyStyle::writeln | [public] Method has been added. | V015 |
MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:343 | Symfony\Component\Console\Style\SymfonyStyle::write | [public] Method has been added. | V015 |
MAJOR | src/Symfony/Component/Console/Style/SymfonyStyle.php:352 | Symfony\Component\Console\Style\SymfonyStyle::newLine | [public] Method has been added. | V015 |
In the best case, it is a matter of playing with the style of the Symfony Console. In the worst, it would require writing a new table generator.
I just gave this a try. This is what's preventing me: https://github.com/symfony/console/blob/master/Helper/Table.php#L261-L276
Note the calls to renderRowSeparator
. For valid markdown tables you need to suppress the very first and last separators. The one right after the header has to be kept. The method is public, but it calls private methods..
Unless you have any ideas, I wouldn't mind writing my own implementation. Excluding col/row spans, pretty sure MD doesn't support that anyway.
@nochso You could probably inherit from the TableHelper
and rewrite the render
function or possibly create a new method like "renderMarkdown" from that same inherited class.
Although my first idea would be to find a way to make Symfony's TableHelper be able to render to markdown out of the box.
Edit: I submitted symfony/symfony#17466. If it gets around being done, we could simply use the markdown style.