You are here

protected function WebformCliService::_drush_webform_docs_tidy in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::_drush_webform_docs_tidy()

Tidy an HTML string.

Parameters

string $html: HTML string to be tidied.

Return value

string A tidied HTML string.

1 call to WebformCliService::_drush_webform_docs_tidy()
WebformCliService::drush_webform_docs in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().

File

src/Commands/WebformCliService.php, line 1034

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

protected function _drush_webform_docs_tidy($html) {

  // Configuration.
  // - http://us3.php.net/manual/en/book.tidy.php
  // - http://tidy.sourceforge.net/docs/quickref.html#wrap
  $config = [
    'show-body-only' => TRUE,
    'wrap' => '10000',
  ];
  $tidy = new \tidy();
  $tidy
    ->parseString($html, $config, 'utf8');
  $tidy
    ->cleanRepair();
  $html = tidy_get_output($tidy);

  // Convert URLs.
  $html = str_replace('"https://www.drupal.org/', '"/', $html);

  // Remove <code> tag nested within <pre> tag.
  $html = preg_replace('#<pre><code>\\s*#', "<code>\n", $html);
  $html = preg_replace('#\\s*</code></pre>#', "\n</code>", $html);

  // Fix code in webform-libraries.html.
  $html = str_replace(' &gt; ', ' > ', $html);

  // Remove space after <br> tags.
  $html = preg_replace('/(<br[^>]*>)\\s+/', '\\1', $html);

  // Convert <pre> to <code>.
  $html = preg_replace('#<hr>\\s*<pre>([^<]+)</pre>\\s+<hr>\\s*<br>#s', '<p><code>\\1</code></p>' . PHP_EOL, $html);

  // Append footer to HTML document.
  $html .= '<hr />' . PHP_EOL . '<p><em>This documentation was generated by the Webform module and <b>MUST</b> be updated using the `drush webform-docs` command.</em></p>';

  // Add play icon.
  $html = str_replace('>Watch video</a>', ' class="link-button">▶ Watch video</a>', $html);
  return $html;
}