-
Notifications
You must be signed in to change notification settings - Fork 0
/
extraspace_filter.module
executable file
·36 lines (31 loc) · 1.08 KB
/
extraspace_filter.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* @file
* Module that filters empty HTML tags and extra non-breaking spaces.
*/
/**
* Implements hook_filter_info().
*/
function extraspace_filter_filter_info() {
$filters['extraspace_filter_filter'] = array(
'title' => t('Filter extra space'),
'description' => t('Filters empty HTML tags and extra non-breaking spaces.'),
'process callback' => 'extraspace_filter_filter_process',
);
return $filters;
}
/**
* Filter process callback.
*
* @see hook_filter_FILTER_process()
*/
function extraspace_filter_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
// Remove empty paragraph tags
$text = preg_replace('/\<p(\s[^\>]*)*\>(\s|\xC2\xA0| )*\<\/p\>/i', '', $text);
// Remove multiple non-breaking spaces
$text = preg_replace('/( )(\n|\r|\t|\s|\xC2\xA0| )+/i', '$1', $text);
// Remove multiple line-breaks
// Cleanup beginnings of paragraphs
$text = preg_replace('/(\<br\>|\<br \/\>|\<p\>)(\n|\r|\t|\s|\xC2\xA0| |\<br\>|\<br \/\>)+/i', '$1', $text);
return $text;
}