You are here

README.txt in Custom filter 5

Custom Filter module provides an ability to create some filter without writing any module.

When we create a new Input Format, we will be asked to choose the filters we want. Some modules hook into filter module and provide additional filters here, e.g. Textile, GeshiFilter, MathFilter. This module do the same thing, except this module allows user to define their own filter.

How do we define our own filters? First, we need to create a filterset. A filterset is a container containing filters. When we create/configure a new Input Format, every defined filterset will appear in the Filters list.

A filterset is only a container. We need to define some real filters if we want it to work. So, an Input Format contains one/more filtersets, each has its own filters.

The most essential part of each filter is pattern and replacement. A pattern is a regular expression like "/(d)rupal/i", to be matched in text. Once the pattern matched, the module will replace the subtext matched with replacement text provided. If we provide "DDD" as replacement text, then "This drupal module works." becomes "This DDDrupal module works."

Every filter can have subfilters. What actually subfilters are? They are exactly the same as filter, except that they match only the substring, not the whole text.

Filter      : MediaWiki Syntax
Pattern     : /\<mwiki\>(.*?)\<\/mwiki\>/i
Replacement : <p>This is mediawiki section.</p>$1<p>End of mediawiki section.</p>
Description : Match strings surrounded by <mwiki>...</mwiki>

Subfilter   : Heading 1
Matches     : 1
Pattern     : /\=(.*?)\=/
Replacement : <h1>$1</h1>
Description : Converts =...= into <h1>...</h1>

If we have text

  This demonstration demonstrates custom filter.
  <mwiki>=Heading1=</mwiki>
  =Heading1=

the text will be

  This demonstration demonstrates custom filter.
  <p>This is mediawiki section.</p><h1>Heading1</h1><p>End of mediawiki section.</p>
  =Heading1=

The first "=Heading1=" is replaced by "<h1>Heading1</h1>", but the second not. Why? Because the "Heading 1" filter is a subfilter of "Mediawiki Syntax", so "Heading 1" will be used only in the string matched by "Mediawiki Syntax", that is the string surrounded by <mwiki>...</mwiki>.

=INSTALLATION=

1. Just copy the entire Custom Filter directory into the module directory, and enable it at Administer/Site Building/Modules. The module will install 2 tables in Drupal database.
3. There will be a new menu item: Administer/Site Configuration/Custom Filter. This will be the administration page of entire filters. Non-administrator user need to have "administer customfilter" permission to use this.
3. To learn about custom filter, you can import "customfilter_sample.xml" provided.

File

README.txt
View source
  1. Custom Filter module provides an ability to create some filter without writing any module.
  2. When we create a new Input Format, we will be asked to choose the filters we want. Some modules hook into filter module and provide additional filters here, e.g. Textile, GeshiFilter, MathFilter. This module do the same thing, except this module allows user to define their own filter.
  3. How do we define our own filters? First, we need to create a filterset. A filterset is a container containing filters. When we create/configure a new Input Format, every defined filterset will appear in the Filters list.
  4. A filterset is only a container. We need to define some real filters if we want it to work. So, an Input Format contains one/more filtersets, each has its own filters.
  5. The most essential part of each filter is pattern and replacement. A pattern is a regular expression like "/(d)rupal/i", to be matched in text. Once the pattern matched, the module will replace the subtext matched with replacement text provided. If we provide "DDD" as replacement text, then "This drupal module works." becomes "This DDDrupal module works."
  6. Every filter can have subfilters. What actually subfilters are? They are exactly the same as filter, except that they match only the substring, not the whole text.
  7. Filter : MediaWiki Syntax
  8. Pattern : /\(.*?)\<\/mwiki\>/i
  9. Replacement :

    This is mediawiki section.

    $1

    End of mediawiki section.

  10. Description : Match strings surrounded by ...
  11. Subfilter : Heading 1
  12. Matches : 1
  13. Pattern : /\=(.*?)\=/
  14. Replacement :

    $1

  15. Description : Converts =...= into

    ...

  16. If we have text
  17. This demonstration demonstrates custom filter.
  18. =Heading1=
  19. =Heading1=
  20. the text will be
  21. This demonstration demonstrates custom filter.
  22. This is mediawiki section.

    Heading1

    End of mediawiki section.

  23. =Heading1=
  24. The first "=Heading1=" is replaced by "

    Heading1

    ", but the second not. Why? Because the "Heading 1" filter is a subfilter of "Mediawiki Syntax", so "Heading 1" will be used only in the string matched by "Mediawiki Syntax", that is the string surrounded by ....
  25. =INSTALLATION=
  26. 1. Just copy the entire Custom Filter directory into the module directory, and enable it at Administer/Site Building/Modules. The module will install 2 tables in Drupal database.
  27. 3. There will be a new menu item: Administer/Site Configuration/Custom Filter. This will be the administration page of entire filters. Non-administrator user need to have "administer customfilter" permission to use this.
  28. 3. To learn about custom filter, you can import "customfilter_sample.xml" provided.