Flexifilter, as of 1.1, provides for importing and exporting. When exporting a flexifilter, you can choose either a PHP version for use in modules, or serialized data for manual imports. To manually import flexifilters, such as those provided below, go to Administer -> Site Building -> Flexifilters, and click 'Import a flexifilter'. To use an export in your module, manually import the export as shown previously, and then export them in PHP format (or you can build them from scratch). Then see the Flexifilter API handbook page.

Please contribute your own flexifilters! If you have documentation status, please edit this page and add them in the format provided. If you don't have documentation status, create a book page with this node as the parent, and someone with documentation status will move them here for you.

Mediawiki Format

The Mediawiki format is a widely used format that is based on the Mediawiki software. It comes pre-installed with Flexifilter, however it is a good example of a flexifilter, and what Flexifilter's exports look like.

Flexifilter Cite

Flexifilter Cite is a sample module, serving as an example of how modules can utilize Flexifilter to distribute a filter. It allows for citations of other nodes to be added as components in flexifilters.

Link Formatting

Sometimes it's difficult to teach users how to use HTML, and instead, you can teach them a format like this: [link|title]. This export provides the flexifilter for this format.

Please note that the previous link is not importing correctly in flexifilter-6.x-1.2. Please import this instead:
a:9:{s:5:"label";s:15:"Link Formatting";s:11:"description";s:47:"You may format links in the format [link|title]";s:2:"id";s:1:"2";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"0";s:5:"cache";s:1:"1";s:10:"components";a:3:{i:0;a:3:{s:5:"class";s:22:"flexifilter_chunk_grab";s:8:"settings";a:7:{s:6:"starts";s:1:"[";s:4:"ends";s:1:"]";s:11:"pass_limits";i:0;s:14:"case_sensitive";i:0;s:12:"include_rest";i:1;s:4:"step";s:7:"process";s:10:"components";a:3:{i:0;a:3:{s:5:"class";s:24:"flexifilter_text_prepend";s:8:"settings";a:2:{s:4:"text";s:9:"<a href="";s:4:"step";s:7:"process";}s:2:"id";s:2:"32";}i:1;a:3:{s:5:"class";s:24:"flexifilter_text_replace";s:8:"settings";a:3:{s:4:"find";s:1:"|";s:7:"replace";s:2:"">";s:4:"step";s:7:"process";}s:2:"id";s:2:"33";}i:2;a:3:{s:5:"class";s:23:"flexifilter_text_append";s:8:"settings";a:2:{s:4:"text";s:4:"</a>";s:4:"step";s:7:"process";}s:2:"id";s:2:"34";}}}s:2:"id";s:2:"31";}s:7:"id_next";i:35;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}

Back to Top

When text is really long and unwieldy, you need a back to top link. Because Flexifilter has if statements, and text appending, we can create such a filter with Flexifilter. See this tutorial and this export.

Swear Filter

If you have a community that allows anyone to post to the front page, you may consider using a swear filter. Here is the export for a starting point- you can add your own swears, using the example (not a real swear!) to guide your filter.

Comments

buzink’s picture

error: It appears that the serialized flexifilter you entered was improperly formed. Please check the source.

mgriffith’s picture

According to MediaWiki formatting rules for external links (http://www.mediawiki.org/wiki/Help:Links#External_links) the format [http://example.com An Example] should be supported (note the use of a space instead of a pipe |)

The export below supports that format and should be applied AFTER the built-in MediaWiki formatter.

a:9:{s:5:"label";s:15:"Link Formatting";s:11:"description";s:48:"You may format links in the format [http://example.com An Example].";s:2:"id";s:1:"2";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:3:{i:0;a:3:{s:5:"class";s:22:"flexifilter_chunk_grab";s:8:"settings";a:7:{s:6:"starts";s:1:"[";s:4:"ends";s:1:"]";s:11:"pass_limits";i:0;s:14:"case_sensitive";i:0;s:12:"include_rest";i:1;s:4:"step";s:7:"process";s:10:"components";a:3:{i:0;a:3:{s:5:"class";s:22:"flexifilter_text_regex";s:8:"settings";a:3:{s:4:"find";s:6:"\s(.*)";s:7:"replace";s:4:"">$1";s:4:"step";s:7:"process";}s:2:"id";s:2:"31";}i:1;a:3:{s:5:"class";s:24:"flexifilter_text_prepend";s:8:"settings";a:2:{s:4:"text";s:9:"<a href="";s:4:"step";s:7:"process";}s:2:"id";s:2:"32";}i:2;a:3:{s:5:"class";s:23:"flexifilter_text_append";s:8:"settings";a:2:{s:4:"text";s:4:"</a>";s:4:"step";s:7:"process";}s:2:"id";s:2:"34";}}}s:2:"id";s:2:"30";}s:7:"id_next";i:35;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
Suitov’s picture

Same problem here. I'm trying to do something more advanced, wanted to use the Link Formatting example as a starting point, but it says it's not valid to import.

David Latapie’s picture

Hi,

I am not a coder. I installed Flexifilters with Drupal 6. I copied some MediaWiki text of mine over Drupal, with ordered list (#). This is not supported. It is possible to make it work without delving into the code?

H5-H6 are not supported either. Same question: a way to fix it without coding?

Thanks

valllabh’s picture

Please check this out, I think its something you needed.
http://drupal.org/node/212417#comment-3852986

valllabh’s picture

MediaWiki Format: Wikipedia like editing http://www.mediawiki.org/wiki/Help:Formatting

Original Work By: Valentin Guignon (valentin.guignon@cirad.fr)
Flexifilter Extension Conversion By: Vallabh Joshi (http://vallabhjoshi.com | vallabhjoshi@gmail.com)

This filter supports:

  • 4 level Order Lists(#) & Unordered Lists (*)
  • 4 level Indention(:)
  • Table Generation
  • Wiki links [[wiki link]]
  • Image files [[image:file]]
  • Media files [[media:file]]

  • horizontal line ----
  • And many more

Please IMPORT code below in Flexifilter

a:9:{s:5:"label";s:16:"MediaWiki Format";s:11:"description";s:63:"This is a format which provides a MediaWiki-style input format.";s:2:"id";s:1:"5";s:7:"enabled";b:1;s:8:"advanced";b:1;s:5:"delta";s:1:"0";s:5:"cache";s:1:"1";s:10:"components";a:3:{i:0;a:3:{s:5:"class";s:24:"flexifilter_advanced_php";s:8:"settings";a:2:{s:4:"code";s:7962:"/*
 * Version: 1.0
 *  Date: 21/12/2010
 *  Original Work By: Valentin Guignon (valentin.guignon@cirad.fr)
 *  Flexifilter Extension Conversion By: Vallabh Joshi (vallabhjoshi.com | vallabhjoshi@gmail.com)
 *  License: GNU GENERAL PUBLIC LICENSE
 *  Mediawiki FlexiFilter Extension
*/

/* url where you put the MediaWiki files;
 * ex.: "http://www.myserver.com/drupal/sites/default/files/wiki/"*/
$url_to_files = url('', array('absolute' => TRUE)).'sites/default/files/wiki/';

/*url used by Wikitools; ex.: "http://www.myserver.com/drupal/?q=wiki/"*/
$url_to_drupal_wiki = url('wiki/');

$patterns = array();
$replacements = array();

/*add EOL to the last line if it contains a Wiki tag*/
array_push($patterns, '/([\n\r](?: |&nbsp;)*[*#:|][^\r\n]+)$/s');
array_push($replacements, "$1\n");

/*= h1 =*/
array_push($patterns, '/^(?: |&nbsp;)*=([^=\n\r][^\n\r]*?)=(?: |&nbsp;)*/m');
array_push($replacements, "<h1>$1</h1>");

/*== h2 ==*/
array_push($patterns, '/^(?: |&nbsp;)*==([^=\n\r][^\n\r]*?)==(?: |&nbsp;)*/m');
array_push($replacements, "<h2>$1</h2>");

/*=== h3 ===*/
array_push($patterns, '/^(?: |&nbsp;)*===([^=\n\r][^\n\r]*?)===(?: |&nbsp;)*/m');
array_push($replacements, "<h3>$1</h3>");

/*==== h4 ====*/
array_push($patterns, '/^(?: |&nbsp;)*====([^=\n\r][^\n\r]*?)====(?: |&nbsp;)*/m');
array_push($replacements, "<h4>$1</h4>");

/* '''bold''' */
array_push($patterns, '/\'\'\'(.+?)\'\'\'/');
array_push($replacements, '<b>$1</b>');

/* ''italic'' */
array_push($patterns, '/\'\'(.+?)\'\'/');
array_push($replacements, '<i>$1</i>');

/* [[image:file|thumb|alt text]] */
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\|thumb\|([^\]\n\r]*)\]\]/i');
array_push($replacements, "<img class=\"mediawiki_thumb\" src=\"$url_to_files$1\" alt=\"$2\"/>");

/* [[image:file|alt text]] */
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+\.(?:jpg|jpeg|png|gif|bmp|ico))\|?([^\]\n\r]*)\]\]/i');
array_push($replacements, "<img src=\"$url_to_files$1\" alt=\"$2\"/>");

/* [[image:file]] */
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+\.(?:jpg|jpeg|png|gif|bmp|ico))\]\]/i');
array_push($replacements, "<img src=\"$url_to_files$1\" alt=\"$1\"/>");

/*no-image files:*/
/* [[image:file|alt text]] */
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\|?([^\]\n\r]*)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$2</a>");

/* [[image:file]] */
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$1</a>");

/* [[media:file]] */
array_push($patterns, '/\[\[Media:([^\|\]"\n\r]+)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$1</a>");

/* [[wiki link|Specified Name]] */
array_push($patterns, '/\[\[([^\|\]"\n\r]+)\|([^\]\n\r]+)\]\]/');
array_push($replacements, "<a href=\"$url_to_drupal_wiki$1\">$2</a>");

/* [[wiki link]] */
array_push($patterns, '/\[\[([^\]"\n\r]+)\]\]/');
array_push($replacements, "<a href=\"$url_to_drupal_wiki$1\">$1</a>");

/* [http://www.url.com/ Named URL] */
array_push($patterns, '/\[(http|https|ftp):\/\/([^\]]+) ([^\]]+)]/');
array_push($replacements, '<a href="$1://$2">$3</a>');

/* [http://www.url.com/] */
array_push($patterns, '/\[(http|https|ftp):\/\/([^\]]+)]/');
array_push($replacements, '<a href="$1://$2">$1://$2</a>');


/* *list of elements*/
array_push($patterns, '/^((?:(?: |&nbsp;)*\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ul class=\"mediawiki\">\n$1</ul>\n");
array_push($patterns, '/^(?: |&nbsp;)*\*([^\*\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/*second level*/
array_push($patterns, '/^((?:(?: |&nbsp;)*\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li style=\"background-image: none;\">\n<ul class=\"mediawiki\">\n$1</ul>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*\*\*([^\*\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/*third level*/
array_push($patterns, '/^((?:(?: |&nbsp;)*\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li style=\"background-image: none;\">\n<ul class=\"mediawiki\">\n$1</ul>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*\*\*\*([^\*\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/*fourth level*/
array_push($patterns, '/^((?:(?: |&nbsp;)*\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li style=\"background-image: none;\">\n<ul class=\"mediawiki\">\n$1</ul>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*\*\*\*\*([^\*\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");

/* # list of elements */
array_push($patterns, '/^((?:(?: |&nbsp;)*#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ol class=\"mediawiki\">\n$1</ol>\n");
array_push($patterns, '/^(?: |&nbsp;)*#([^#\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/* second level */
array_push($patterns, '/^((?:(?: |&nbsp;)*#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li>\n<ol class=\"mediawiki\">\n$1</ol>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*##([^#\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/* third level */
array_push($patterns, '/^((?:(?: |&nbsp;)*#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li>\n<ol class=\"mediawiki\">\n$1</ol>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*###([^#\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");
/* fourth level */
array_push($patterns, '/^((?:(?: |&nbsp;)*#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<li>\n<ol class=\"mediawiki\">\n$1</ol>\n</li>\n");
array_push($patterns, '/^(?: |&nbsp;)*####([^#\r\n].*)$/m');
array_push($replacements, "<li>$1</li>");

/* : indented elements */
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^:\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dl class=\"mediawiki\">\n$1</dl>\n");
array_push($patterns, '/^(?: |&nbsp;)*:([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
/* second level */
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl class=\"mediawiki\">\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
/* third level */
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl class=\"mediawiki\">\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*:::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
/* fourth level */
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl class=\"mediawiki\">\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*::::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");

/* tables */
array_push($patterns, '/^(?: |&nbsp;)*\{\|(.*?)[\r\n](?:\|\+([^\r\n]*)[\r\n]+)?\|-[^|]*?\|(?:[^|\n\r]*\|)?(.*?)[\r\n]+\|\}/ms');
array_push($replacements, "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"1\" border=\"1\" align=\"center\" class=\"mediawiki_table\">\n<caption class=\"mediawiki_table_legend\">$2</caption>\n<tbody>\n<tr>\n<td>$3\n&nbsp;</td>\n</tr>\n</tbody>\n</table>\n");
/* <tr></tr> */
array_push($patterns, '/^(?: |&nbsp;)*\|-[^|]*?\|(?:[^|\n\r]*\|)?/m');
array_push($replacements, "&nbsp;</td>\n</tr>\n<tr>\n<td>");
/* <td></td> */
array_push($patterns, '/^(?: |&nbsp;)*\|(?:[^|\n\r]*\|)?/m');
array_push($replacements, "&nbsp;</td>\n<td>");

/* ---- */
array_push($patterns, '/----+/');
array_push($replacements, '<hr/>');

/* {{Model}} */
array_push($patterns, '/\{\{[^\}"\n\r]+\}\}/');
array_push($replacements, '');

/* End of lines (not preceded by a HTML tag) */
array_push($patterns, '/([^>] *)(?:\r\n|\n|\r)/s');
array_push($replacements, "$1<br/>\n");

$new_text = preg_replace($patterns, $replacements, $text);

return $new_text;";s:4:"step";s:7:"process";}s:2:"id";s:4:"1526";}s:7:"id_next";i:1527;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
fudokai’s picture

I've tried this a few times (just in case I hadn't grabbed the whole thing) but every time I try to paste this into an import window I get

It appears that the serialized flexifilter you entered was improperly formed. Please check the source.

Is there any chance you can re-post this or make it available as a download?

Running: Drupal 6.20, flexifilter-6.x-1.2 (on openSUSE Linux 11.3)

Alan

risca’s picture

Hello,
starting from the previous filter I've improved a lot the list markup, other minor things, and even add the paragraph tag (<p>).

Now I still have to work on tables (that will be much longer...).

In any case remember that the corret mediawiki syntax is over here: http://www.mediawiki.org/wiki/Help:Formatting http://www.mediawiki.org/wiki/Help:Tables

For next improvement see here: Mediawiki Flexifilter filter

So, that's what you need to import:

a:9:{s:5:"label";s:25:"Mediawiki Extended Format";s:11:"description";s:83:"Filter for MediaWiki content which replace wiki codes by the appropriate HTML tags.";s:2:"id";s:1:"3";s:7:"enabled";b:1;s:8:"advanced";b:1;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:5:{i:0;a:3:{s:5:"class";s:24:"flexifilter_text_prepend";s:8:"settings";a:2:{s:4:"text";s:8:"<nowiki>";s:4:"step";s:7:"process";}s:2:"id";s:2:"84";}i:1;a:3:{s:5:"class";s:23:"flexifilter_text_append";s:8:"settings";a:2:{s:4:"text";s:9:"</nowiki>";s:4:"step";s:7:"process";}s:2:"id";s:2:"85";}i:2;a:3:{s:5:"class";s:22:"flexifilter_chunk_grab";s:8:"settings";a:7:{s:6:"starts";s:8:"<nowiki>";s:4:"ends";s:9:"</nowiki>";s:11:"pass_limits";i:0;s:14:"case_sensitive";i:0;s:12:"include_rest";i:1;s:4:"step";s:7:"process";s:10:"components";a:1:{i:0;a:3:{s:5:"class";s:24:"flexifilter_advanced_php";s:8:"settings";a:2:{s:4:"code";s:9277:"// this script behave as mediawiki formatting: http://www.mediawiki.org/wiki/Help:Formatting
// There are some difference as:
// - top tag and top anchor

$patterns = array();
$replacements = array();
// url where you put the MediaWiki files;
//    ex.: "http://www.myserver.com/drupal/sites/default/files/mediawiki/"
$url_to_files = url('', array('absolute' => TRUE))
                . 'sites/default/files/';
// url used by Wikitools; ex.: "http://www.myserver.com/drupal/?q=wiki/"
$url_to_drupal_wiki = url('wiki/');
$top_name = "#top";

// add EOL to the last line in any case:
array_push($patterns, '/(.*$)/s');
array_push($replacements, "$1\n");

// == h2 == // get top tag
array_push($patterns, '/^(?: |&nbsp;)*==([^=\n\r][^\n\r]*?)==(?: |&nbsp;)*/m');
//array_push($replacements, "<h2>$1</h2>");
array_push($replacements, "<a href=\"$top_name\">top</a>\n<h2>$1</h2>");

// === h3 ===
array_push($patterns, '/^(?: |&nbsp;)*===([^=\n\r][^\n\r]*?)===(?: |&nbsp;)*/m');
array_push($replacements, "<h3>$1</h3>");

// ==== h4 ====
array_push($patterns, '/^(?: |&nbsp;)*====([^=\n\r][^\n\r]*?)====(?: |&nbsp;)*/m');
array_push($replacements, "<h4>$1</h4>");

// ===== h5 =====
array_push($patterns, '/^(?: |&nbsp;)*=====([^=\n\r][^\n\r]*?)=====(?: |&nbsp;)*/m');
array_push($replacements, "<h5>$1</h5>");

//// problem, what about if they are on multiple lines?
// '''bold'''
array_push($patterns, '/\'\'\'(.+?)\'\'\'/');
array_push($replacements, '<b>$1</b>');

// ''italic''
array_push($patterns, '/\'\'(.+?)\'\'/');
array_push($replacements, '<i>$1</i>');

// [[image:file|thumb|alt text]]
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\|thumb\|([^\]\n\r]*)\]\]/i');
array_push($replacements, "<img src=\"$url_to_files$1\" alt=\"$2\"/>");

// [[image:file|alt text]]
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+\.(?:jpg|jpeg|png|gif|bmp|ico))\|?([^\]\n\r]*)\]\]/i');
array_push($replacements, "<img src=\"$url_to_files$1\" alt=\"$2\"/>");

// [[image:file]]
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+\.(?:jpg|jpeg|png|gif|bmp|ico))\]\]/i');
array_push($replacements, "<img src=\"$url_to_files$1\" alt=\"$1\"/>");

// no-image files:
// [[image:file|alt text]]
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\|?([^\]\n\r]*)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$2</a>");

// [[image:file]]
array_push($patterns, '/\[\[Image:([^\|\]"\n\r]+)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$1</a>");

// [[media:file]]
array_push($patterns, '/\[\[Media:([^\|\]"\n\r]+)\]\]/i');
array_push($replacements, "<a href=\"$url_to_files$1\">$1</a>");

// [[wiki link|Specified Name]]
array_push($patterns, '/\[\[([^\|\]"\n\r]+)\|([^\]\n\r]+)\]\]/');
array_push($replacements, "<a href=\"$url_to_drupal_wiki$1\">$2</a>");

// [[wiki link]]
array_push($patterns, '/\[\[([^\]"\n\r]+)\]\]/');
array_push($replacements, "<a href=\"$url_to_drupal_wiki$1\">$1</a>");

// [http://www.url.com/ Named URL]
array_push($patterns, '/\[(http|https|ftp):\/\/([^\]]+) ([^\]]+)]/');
array_push($replacements, '<a href="$1://$2">$3</a>');

// [http://www.url.com/]
array_push($patterns, '/\[(http|https|ftp):\/\/([^\]]+)]/');
array_push($replacements, '<a href="$1://$2">$1://$2</a>');

// LIST order and unorder
// mark list block level 1
array_push($patterns, '/^(?:(?: |&nbsp;)*\*[^\r\n][^\r\n]*[\r\n]{1,2})+/ms');
array_push($replacements, "<ul1>\n$0</ul1>\n");
array_push($patterns, '/^((?:(?: |&nbsp;)*#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ol1>\n$1</ol1>\n");
// mark list block level 2
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*]\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ul2>\n$1</ul2>\n");
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*]#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ol2>\n$1</ol2>\n");
// mark list block level 3
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*][#\*]\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ul3>\n$1</ul3>\n");
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*][#\*]#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ol3>\n$1</ol3>\n");
// mark list block level 4
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*][#\*][#\*]\*[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ul4>\n$1</ul4>\n");
array_push($patterns, '/^((?:(?: |&nbsp;)*[#\*][#\*][#\*]#[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<ol4>\n$1</ol4>\n");
// set level 4 item
array_push($patterns, '/^(?: |&nbsp;)*[#\*][#\*][#\*][#\*]([^#\*\r\n].*)$/m');
array_push($replacements, "<li>$1</li>\n");
// mark level 3 item
array_push($patterns, '/^(?: |&nbsp;)*[#\*][#\*][#\*]([^#\*\r\n].*)$/m');
array_push($replacements, "<li3>$1</li3>\n");
// mark level 2 item
array_push($patterns, '/^(?: |&nbsp;)*[#\*][#\*]([^#\*\r\n].*)$/m');
array_push($replacements, "<li2>$1</li2>\n");
// mark level 1 item
array_push($patterns, '/^(?: |&nbsp;)*[#\*]([^#\*\r\n].*)$/m');
array_push($replacements, "<li1>$1</li1>\n");
// correct the nesting
// the begining of the nesting (level 2)
array_push($patterns, '/<\/li1>[^(<li>)]*<([ou]l2)>/ms');
array_push($replacements, "<$1>");
array_push($patterns, '/<([ou]l1)>[^(<li>)]*<([ou]l2)>/ms');
array_push($replacements, "<$1><li1><$2>");
// and where it ends (level 2)
array_push($patterns, '/<\/([ou]l2)>[^(<ul.>|<ol.>)]*<li1>/ms');
array_push($replacements, "</$1></li1><li1>");
array_push($patterns, '/<\/([ou]l2)>[^(<ul.>|<ol.>)]*<\/([ou]l1)>/ms');
array_push($replacements, "</$1></li1></$2>");
// the begining of the nesting (level 3)
array_push($patterns, '/<\/li2>[^(<li>)]*<([ou]l3)>/ms');
array_push($replacements, "<$1>");
array_push($patterns, '/<([ou]l2)>[^(<li>)]*<([ou]l3)>/ms');
array_push($replacements, "<$1><li2><$2>");
//and where it ends (level 3)
array_push($patterns, '/<\/([ou]l3)>[^(<ul.>|<ol.>)]*<li2>/ms');
array_push($replacements, "</$1></li2><li2>");
array_push($patterns, '/<\/([ou]l3)>[^(<ul.>|<ol.>)]*<\/([ou]l2)>/ms');
array_push($replacements, "</$1></li2></$2>");
// the begining of the nesting (level 4)
array_push($patterns, '/<\/li3>[^(<li>)]*<([ou]l4)>/ms');
array_push($replacements, "<$1>");
array_push($patterns, '/<([ou]l3)>[^(<li>)]*<([ou]l4)>/ms');
array_push($replacements, "<$1><li3><$2>");
//and where it ends (level 4)
array_push($patterns, '/<\/([ou]l4)>[^(<ul.>|<ol.>)]*<li3>/ms');
array_push($replacements, "</$1></li3><li3>");
array_push($patterns, '/<\/([ou]l4)>[^(<ul.>|<ol.>)]*<\/([ou]l3)>/ms');
array_push($replacements, "</$1></li3></$2>");
// clean all the remaining mark up
array_push($patterns, '/<(\/?(li|[ou]l))[1234]>/');
array_push($replacements, "<$1>");

////////// TO TEST
// : indented elements
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^:\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dl>\n$1</dl>\n");
array_push($patterns, '/^(?: |&nbsp;)*:([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
// second level
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl>\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
// third level
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl>\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*:::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");
// fourth level
array_push($patterns, '/^((?:(?: |&nbsp;)*:[^\r\n][^\r\n]*[\r\n]{1,2})+)/ms');
array_push($replacements, "<dd>\n<dl>\n$1</dl>\n</dd>\n");
array_push($patterns, '/^(?: |&nbsp;)*::::([^:\r\n].*)$/m');
array_push($replacements, "<dd>$1</dd>");

///////////TO TEST
// tables
array_push($patterns, '/^(?: |&nbsp;)*\{\|(.*?)[\r\n](?:\|\+([^\r\n]*)[\r\n]+)?\|-[^|]*?\|(?:[^|\n\r]*\|)?(.*?)[\r\n]+\|\}/ms');
array_push($replacements, "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"1\" border=\"1\" align=\"center\" class=\"mediawiki_table\">\n<caption class=\"mediawiki_table_legend\">$2</caption>\n<tbody>\n<tr>\n<td>$3\n&nbsp;</td>\n</tr>\n</tbody>\n</table>\n");
// <tr></tr>
array_push($patterns, '/^(?: |&nbsp;)*\|-[^|]*?\|(?:[^|\n\r]*\|)?/m');
array_push($replacements, "&nbsp;</td>\n</tr>\n<tr>\n<td>");
// <td></td>
array_push($patterns, '/^(?: |&nbsp;)*\|(?:[^|\n\r]*\|)?/m');
array_push($replacements, "&nbsp;</td>\n<td>");

// ----
array_push($patterns, '/----+/');
array_push($replacements, '<hr/>');

// set paragraph tag
array_push($patterns, "/^[^\n\r]*?<((?!(strong|b|em|br|tt|a|u|s|del|strike|font)\b)[a-z0-9]+).*?>.*?<\/\\1>[^\n\r]*/sim");
array_push($replacements,  "\n<noP>$0</noP>\n");
array_push($patterns, "/^(^[^\n\r]*?<((?=noP\b)[a-z0-9]+)>)?(?(1).*?<\/\\2>[^\n\r]*|^([^\n\r].+?)(?=([\n\r]<noP>|[\n\r]{2})))/sim");
array_push($replacements, "<p>$0</p>\n");
array_push($patterns, "/^<p>(?: |&nbsp;)*[\r\n]{0,2}<noP>/m");
array_push($replacements, "");
array_push($patterns, "/<\/noP>(?: |&nbsp;)*[\r\n]{0,2}<\/p>/m");
array_push($replacements, "");

$new_text = preg_replace($patterns, $replacements, $text);

return $new_text;";s:4:"step";s:7:"process";}s:2:"id";s:2:"87";}}}s:2:"id";s:2:"86";}s:7:"id_next";i:88;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
wvd_vegt’s picture

Hi Risca

It's an old thread (and old sandbox code) but did you ever managed to fix the display of the last table cell (bottom/right one). It is missing in the table and output as a P tag inside the table or as an attribute name sometimes depending on the table data.

regards
wvdv