Skip to content

Instantly share code, notes, and snippets.

@typhonius
Last active February 11, 2019 08:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typhonius/5046260 to your computer and use it in GitHub Desktop.
Save typhonius/5046260 to your computer and use it in GitHub Desktop.
A filter format for applying greentext correctly to Drupal text. The snippet will provide any filter format with the ability to change any line starting with '>' into a greentext line. >Implying anyone will use it
<?php
function greentext_filter_info() {
$filters['greentext'] = array(
'title' => t('Implying greentext'),
'description' => t('Allows you to alter any lines input starting with \'>\' to appear as greentext.'),
'process callback' => '_greentext_greentext',
'tips callback' => '_greentext_greentext_tips',
);
return $filters;
}
function _greentext_greentext($text, $filter) {
$lines = explode("\n", $text);
foreach ($lines as $index => $line) {
if (preg_match('/^>/', strip_tags($line), $matches)) {
$lines[$index] = theme('greentext', array('text' => $line));
}
}
$text = implode("\n", $lines);
return $text;
}
function _greentext_greentext_tips($filter, $format, $long = FALSE) {
$output = t('Lines beginning with \'>\' will automatically be replaced with greentext');
return $output;
}
function greentext_theme($existing, $type, $theme, $path) {
return array(
'greentext' => array(
'template' => 'greentext',
'variables' => array('text' => NULL),
),
);
}
<?php
// Put this in a CSS file and add class.
print '<span style="color:#789922">' . $text . '</span>';
@AugustGarcia
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment