EditLive's XHTML and HTML output can be configured using a large range of configuration options, however from time to time you may wish to fine-tune the generated HTML. For example:
- getting more control over code formatting
- supporting custom HTML tags
To accomplish this, we'll take advantage of EditLive Enterprise Edition's Advanced APIs to write a custom source filter. 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 (see attached) 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:
This example can be installed and run using the Ephox Plug-in architecture. As source filters work early in the documents lifecyle they should be loaded using the early loading option. See: Including a Plugin in EditLive v7.
The source filter plugin.xml would look something like this:
<?xml version="1.0" encoding="US-ASCII" ?>
It assumes that the SimpleSourceFilter class has been compiled and put into the SimpleSourceFilter jar file.