Source Filters In EditLive!
EditLive! does an excellent job of producing standards compliant XHTML, and HTML. The output can be configured using a large range of configuration options, however from time to time you may want to control the HTML that is generated by EditLive! There can be many reasons for wanting to do this, from the simple cases of wanting to have control over formatting, to cases where custom HTML tags are used (like in some CMS).
It is possible to step outside the constraints of the configuration file, and take advantage of the Advanced APIs to write a custom source filter to be used with EditLive!. A source filter makes it possible to change the HTML that works with EditLive!, either when the HTML is coming out of the design view, or when the code is going into the the design view.
The SourceFilter is a simple Java interface, with two methods:
filterIn (filter html going into the design mode of EditLive!)
filterOut (filter html going out of the design mode).
These methods both have a single string parameter (the html text) and return a string (the output html).
The Simple Source Filter java class contains a simple source filter implementation that minimizes the amount of space that list items take in the output. This is done with a regular expression.
The code in this filter changes:
<li>
hello
</li>
to:
<li>hello</li>
This example (and others) can be installed and run using the Ephox Plug-in architecture (described in this liveworks article). As source filters work early in the documents lifecyle they should be loaded using the early loading option.
The source filter plugin.xml would look something like this:
<?xml version="1.0" encoding="US-ASCII" ?>
<plugin load="early">
<advancedapis
jar="SimpleSourceFilter.jar"
class="com.ephox.example.SimpleSourceFilter" />
</plugin>
It assumes that the SimpleSourceFilter class has been compiled and put into the SimpleSourceFilter jar file.


January 15th, 2008 at 8:46 pm
I need to remove the tags from the body of the source. In the code
source = matcher.replaceAll(”$1″);
How do I use the filter to remove the tags from the source??
thanks
Kanji
January 15th, 2008 at 9:52 pm
Hi Kanji,
Within the filterIn or filterOut method you can use any method you like to modify the content - you just have to return a String as the result.