/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); // Track if widget has been found so that we can attached the // jquery_ui_filter library and settings. $has_widget = FALSE; foreach (self::$widgets as $name => $widget) { if (strpos($text, '[' . $name) === FALSE) { continue; } $has_widget = TRUE; // Remove block tags around tokens. $text = preg_replace('#<(p|div)[^>]*>\\s*(\\[/?' . $name . '[^]]*\\])\\s*</\\1>#', '\\2', $text); // Convert opening [token] to opening <div data-ui-*> tag. $text = preg_replace_callback('#\\[' . $name . '([^]]*)?\\]#is', function ($match) use($name) { // Set data-ui-* attributes from role and options. $attributes = new Attribute(['data-ui-role' => $name]); $options = $this->parseOptions($match[1]); foreach ($options as $name => $value) { $attributes->setAttribute('data-ui-' . $name, $value); } return "<div{$attributes}>"; }, $text); // Convert closing [/token] to closing </div> tag. $text = str_replace('[/' . $name . ']', '</div>', $text); } if ($has_widget) { $result->setAttachments(['library' => ['jquery_ui_filter/jquery_ui_filter'], 'drupalSettings' => ['jquery_ui_filter' => \Drupal::config('jquery_ui_filter.settings')->get()]]); } return $result->setProcessedText($text); }
/** * {@inheritdoc} */ public function process($text, $langcode) { $invitation = $this->settings['celebrate_invitation'] ? ' Come on!' : ''; $replace = '<span class="celebrate-filter">' . $this->t('Good Times!' . $invitation) . '</span>'; $new_text = str_replace('[celebrate]', $replace, $text); $result = new FilterProcessResult($new_text); $result->setAttachments(array('library' => array('custom_filters/celebrate-shake'))); return $result; }
/** * {@inheritdoc} */ public function process($text, $langcode) { // Supporting both [fn] and <fn> now. Thanks to fletchgqc // http://drupal.org/node/268026. // Convert all square brackets to angle brackets. This way all further code // just manipulates angle brackets. (Angle brackets are preferred here for // the simple reason that square brackets are more tedious to use in // regexps). $text = preg_replace('|\\[fn([^\\]]*)\\]|', '<fn$1>', $text); $text = preg_replace('|\\[/fn\\]|', '</fn>', $text); $text = preg_replace('|\\[footnotes([^\\]]*)\\]|', '<footnotes$1>', $text); // Check that there are an even number of open and closing tags. // If there is one closing tag missing, append this to the end. // If there is more disparity, throw a warning and continue. // A closing tag may sometimes be missing when we are processing a teaser // and it has been cut in the middle of the footnote. // See http://drupal.org/node/253326 $foo = array(); $open_tags = preg_match_all("|<fn([^>]*)>|", $text, $foo); $close_tags = preg_match_all("|</fn>|", $text, $foo); if ($open_tags == $close_tags + 1) { $text = $text . '</fn>'; } elseif ($open_tags > $close_tags + 1) { trigger_error(t("You have unclosed fn tags. This is invalid and will\n produce unpredictable results.")); } // Before doing the replacement, the callback function needs to know which // options to use. $this->replaceCallback($this->settings['footnotes_collapse'], 'prepare'); $pattern = '|<fn([^>]*)>(.*?)</fn>|s'; $text = preg_replace_callback($pattern, array($this, 'replaceCallback'), $text); // Replace tag <footnotes> with the list of footnotes. // If tag is not present, by default add the footnotes at the end. // Thanks to acp on drupal.org for this idea. see // http://drupal.org/node/87226. $footer = $this->replaceCallback(NULL, 'output footer'); $pattern = '|(<footnotes([^\\]]*)>)|'; if (preg_match($pattern, $text) > 0) { $text = preg_replace($pattern, $footer, $text, 1); } else { $text .= "\n\n" . $footer; } $result = new FilterProcessResult($text); $result->setAttachments(array('library' => array('footnotes/footnotes'))); return $result; }
/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); try { // Load GeSHi library (if not already). $geshi_library = libraries_load('geshi'); if (!$geshi_library['loaded']) { throw new \Exception($geshi_library['error message']); } // Get the available tags. list($generic_code_tags, $language_tags, $tag_to_lang) = $this->getTags(); if (in_array(GeshiFilter::BRACKETS_PHPBLOCK, array_filter($this->tagStyles()))) { $language_tags[] = 'questionmarkphp'; $tag_to_lang['questionmarkphp'] = 'php'; } $tags = array_merge($generic_code_tags, $language_tags); // Escape special (regular expression) characters in tags (for tags like // 'c++' and 'c#'). $tags = preg_replace('#(\\+|\\#)#', '\\\\$1', $tags); $tags_string = implode('|', $tags); // Pattern for matching the prepared "<code>...</code>" stuff. $pattern = '#\\[geshifilter-(' . $tags_string . ')([^\\]]*)\\](.*?)(\\[/geshifilter-\\1\\])#s'; $text = preg_replace_callback($pattern, array($this, 'replaceCallback'), $text); // Create the object with result. $result = new FilterProcessResult($text); // Add the css file when necessary. if ($this->config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) { $result->setAttachments(array('library' => array('geshifilter/geshifilter'))); } // Add cache tags, so we can re-create the node when some geshifilter // settings change. $cache_tags = array('geshifilter'); $result->addCacheTags($cache_tags); } catch (\Exception $e) { watchdog_exception('geshifilter', $e); drupal_set_message($geshi_library['error message'], 'error'); } return $result; }