You are here

public function ShortcodeService::postprocessText in Shortcode 8

Same name and namespace in other branches
  1. 2.0.x src/ShortcodeService.php \Drupal\shortcode\ShortcodeService::postprocessText()

Provides Html corrector for wysiwyg editors.

Correcting p elements around the divs. <div> elements are not allowed in <p> so remove them.

Parameters

string $text: Text to be processed.

string $langcode: The language code of the text to be filtered.

\Drupal\filter\Plugin\FilterInterface $filter: The filter plugin that triggered this process.

Return value

string The processed string.

File

src/ShortcodeService.php, line 369

Class

ShortcodeService
Provide the ShortCode service.

Namespace

Drupal\shortcode

Code

public function postprocessText($text, $langcode, FilterInterface $filter = NULL) {

  // preg_match_all('/<p>s.*<!--.*-->.*<div/isU', $text, $r);
  // dpm($r, '$r');
  // Take note these are disrupted by the comments inserted by twig debug
  // mode.
  $patterns = [
    '|#!#|is',
    '!<p>(&nbsp;|\\s)*(<\\/*div>)!is',
    '!<p>(&nbsp;|\\s)*(<div)!is',
    // '!<p>(&nbsp;|\s)*(<!--(.*?)-->)*(<div)!is', // Trying to ignore HTML
    // comments.
    '!(<\\/div.*?>)\\s*</p>!is',
    '!(<div.*?>)\\s*</p>!is',
  ];
  $replacements = [
    '',
    '\\2',
    '\\2',
    // '\\3',.
    '\\1',
    '\\1',
  ];
  return preg_replace($patterns, $replacements, $text);
}