thephpleague / html-to-markdown

Convert HTML to Markdown with PHP
MIT License
1.77k stars 205 forks source link

Tables to markdown #131

Closed SL-Gundam closed 5 years ago

SL-Gundam commented 7 years ago

Is this library capable of converting a html table to markdown?

If not then this would be a feature request

colinodell commented 7 years ago

I'd like for any new features to align with the CommonMark spec. Because CommonMark does not (yet) define syntax for tables, I'm hesitant to include it here - instead, I'd prefer to see tables implemented as an addon library.

AntonSmatanik commented 7 years ago

I need this functionality too, thanks for taking care.

Mark-H commented 6 years ago

Needed this as well, so built one here: https://github.com/Mark-H/Docs/blob/2.x/convert/util/TableConverter.php

Load it into your converter instance like this:

        $environment = Environment::createDefaultEnvironment($options);
        $environment->addConverter(new TableConverter());
        $this->converter = new HtmlConverter($environment);
colinodell commented 6 years ago

@Mark-H Nice! If you wanted to release that as a standalone package (that others can easily composer require into their own projects) I'd be happy to give it a prominent link on our README :)

xprt64 commented 5 years ago

@colinodell I wrapped the converter from @Mark-H into an installable package here: https://github.com/xprt64/php-markdown-table-converter and added one unittest.

matthewyeow commented 5 years ago

Hey there, is there any way to convert from Markdown table back to HTML? The CommonMark converter seems to not be able to do it. I've found an issue under TableConverter.php Line 48 case 'thead': $headerLine = reset($element->getChildren())->getValue(); $headers = explode(' | ', trim(trim($headerLine, "\n"), '|'));

Getting the Error: ErrorException: Only variables should be passed by reference

To make it work: moved out the function call to a resulting variable: $children = $element->getChildren(); $headerLine = reset($children)->getValue();

By the way great work.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.