3 use Drupal\Core\Render\Markup;
4 use Drush\Utils\StringUtils;
7 * @defgroup outputfunctions Process output text.
12 * Prints a message with optional indentation. In general,
13 * $this->>logger()->$method($message) is often a better choice than this function.
14 * That gets your confirmation message (for example) into the logs for this
15 * drush request. Consider that Drush requests may be executed remotely and
19 * The message to print.
21 * The indentation (space chars)
23 * File handle to write to. NULL will write
24 * to standard output, STDERR will write to the standard
25 * error. See http://php.net/manual/en/features.commandline.io-streams.php
27 * Add a "\n" to the end of the output. Defaults to TRUE.
30 * Use $this->output()->writeln() in a command method.
32 function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE) {
33 $msg = str_repeat(' ', $indent) . (string)$message;
37 if (($charset = drush_get_option('output_charset')) && function_exists('iconv')) {
38 $msg = iconv('UTF-8', $charset, $msg);
43 fwrite($handle, $msg);
47 * Rudimentary translation system, akin to Drupal's t() function.
50 * String to process, possibly with replacement item.
52 * An associative array of replacement items.
55 * The processed string.
57 function dt($string, $args = []) {
58 return StringUtils::interpolate($string, $args);
62 * Convert html to readable text. Compatible API to
63 * drupal_html_to_text, but less functional. Caller
64 * might prefer to call drupal_html_to_text if there
65 * is a bootstrapped Drupal site available.
68 * The html text to convert.
71 * The plain-text representation of the input.
73 function drush_html_to_text($html, $allowed_tags = NULL) {
75 '<hr>' => '------------------------------------------------------------------------------',
85 $text = str_replace(array_keys($replacements), array_values($replacements), $html);
86 return html_entity_decode(preg_replace('/ *<[^>]*> */', ' ', $text));
90 * @} End of "defgroup outputfunctions".