Welcome! » Log In » Create A New Profile

Developing a plug-in for presentation MathML

Posted by patnaik 
Developing a plug-in for presentation MathML
July 14, 2007 07:16PM

I want to try to write some code so HTMLPurifier can also work through presentation MathML -- some 31 elements and 40-50 attributes. Perhaps I can use $def->addElement in the scripts that will use HP to detail out the rules, but it would be better to code a module/plugin. Then it would be easier (for others as well) to improve the code.

Using the MathML DTD and W3C specs, I have largely delineated the core attributes common to all elements, the element-specific attributes, the attribute value rules (CDATA, required, optional, etc.), the parent-child restrictions, etc.

I am going through the docs to know the prescribed way for coding such an 'external' module/plugin, but haven't been able to figure it out yet. Perhaps, someone can help me here. E.g., I wonder if I should create file PresentationMathML.php inside HTMLPurifier/HTMLModule with code like this ...

class HTMLPurifier_HTMLModule_PresentationMathML extends HTMLPurifier_HTMLModule { var $name = 'PresentationMathML';

... and so on.

This will also help those thinking of making modules/plugins for other non-XHTML XML. Some specific questions:

  1. Where should one place files with the code for looking up the rules/definitions of entities, attributes and elements of the XML?
  2. How should one invoke the module represented by the files?
  3. What naming rules should one follow?
  4. Would it be possible to run HP with just the non-XHTML module?

Thank you.

Re: Developing a plug-in for presentation MathML
July 16, 2007 08:31AM
but it would be better to code a module/plugin. Then it would be easier (for others as well) to improve the code.

Agreed. addElement() is only a convenience for when you need to add one or two new elements.

I am going through the docs to know the prescribed way for coding such an 'external' module/plugin, but haven't been able to figure it out yet. Perhaps, someone can help me here.

There are currently no tutorials for creating an actual module. The syntax, however, is basically identical to that of the Advanced API. Also, the other files in HTMLModule/ should serve as good templates.

Where should one place files with the code for looking up the rules/definitions of entities, attributes and elements of the XML?

In the module file, except for the entities. You'll need to add those in manually to HTMLPurifier_EntityLookup.

How should one invoke the module represented by the files?
$def =& $config->getHTMLDefinition(true)
$def->manager->addModule(new HTMLPurifier_HTMLModule_PresentationMathML());

Don't forget to define a definition ID.

What naming rules should one follow?

That's generally not a problem. Namespacing is a good idea.

Would it be possible to run HP with just the non-XHTML module?

Yes. You'll need to define a new doctype.

Main word of warning: HTML Purifier is not namespace aware, so whatever namespace you pick for your MathML elements, that's what it must be in the input HTML.

Re: Developing a plug-in for presentation MathML
July 16, 2007 07:17PM

Thank you.

Sorry, you do not have permission to post/reply in this forum.