Instead of stripping certain HTML tags (such as em, strong, etc) we should use ANSI escape sequences to format the text.

Comments

deviantintegral’s picture

Status: Active » Needs work
StatusFileSize
new4.48 KB

First bit of refactoring. Doesn't actually hook into drush_html_to_text yet.

deviantintegral’s picture

Status: Needs work » Needs review
StatusFileSize
new14.95 KB

I ended up doing a few things for this:

  • Refactoring the ANSI formatting into it's own function.
  • Converting drush_html_to_text() to use DOMDocument instead of regular expressions.
  • Adding support to replace tags with ANSI equivalents where possible.

Some of the code might be a little verbose for what it is, but I'm guessing that there will be other tags and terminal escapes that might be supported later. With the code as-is, it's relatively simple to add in new tag mappings into each function without having to hack through a regex.

The attached is from format-patch to make it easy to follow along, but feel free to squish or rebase as seen fit.

greg.1.anderson’s picture

Status: Needs review » Needs work

This is pretty awesome. drush topic -y docs-bastion prints out styled text. n.b. -y forces drush to directly print the file to stdout. Without -y, drush paginates the output with 'less'. The output then looks like this:

In ESC[1m.ssh/config:ESC[0m

The ESC are rendered in inverse. If you use 'more' instead of 'less' (change drush_print_file, or make sure 'less' is not in your $PATH), then the output comes out correctly. man bash correctly renders bold text et.al with less pagination, so I am not sure why it is not working here.

kenorb’s picture

Version: » All-versions-4.x-dev
greg.1.anderson’s picture

Version: All-versions-4.x-dev » 8.x-6.x-dev

It would be great if someone could figure out a good way to automatically suppress the color when 'less' was in use, or make the output coloration look right in 'less'.

moshe weitzman’s picture

Title: Use text formatting when rendering HTML » Use text formatting when rendering HTML (e.g. help topics)
moshe weitzman’s picture

Anyone available to push this along?

greg.1.anderson’s picture

Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.