I would like drupal_html_to_text() to have at least a rudimentary handling of tables. At a minimum, it would be good to have a LF to replace the </tr> tag. I am currently thinking to use a tab where the </td> and </th>tags appear.

I am working on a patch, but it is going slow because I am learning regular expressions in the process.

CommentFileSizeAuthor
#1 html2txt.patch2.31 KBkswan

Comments

kswan’s picture

Status: Active » Needs review
StatusFileSize
new2.31 KB

Attached is a patch that adds table functionality to the html_to_text() function. The pipe character is used to delimit the fields and a tab character is used to provide basic alignment of the columns (unfortunately the tabs are removed from this post).

Here is an example of the output:

|field_1	|field_2	|field_3	|field_4	|
|item 1	|item 2	|item 3	|item 4	|
|item 5	|item 6	|item 7	|item 8	|
|item 9	|item10	|item 11	|item 12	|
samikhemiri’s picture

Assigned: Unassigned » samikhemiri
Issue tags: +$pager_total
damien tournoud’s picture

Version: 6.9 » 8.x-dev
Assigned: samikhemiri » Unassigned
Issue tags: -$pager_total

Bumping to Drupal 8, now :(

pillarsdotnet’s picture

Status: Needs review » Needs work

Please consider merging this with the code in #299138-148: Improve \Drupal\Core\Utility\Mail::htmlToText()

pillarsdotnet’s picture

Status: Needs work » Closed (duplicate)

Closing this as the latest version of #299138: Improve \Drupal\Core\Utility\Mail::htmlToText() has excellent table support.