The visual editor API provides interfaces to add custom parsers. This allows developers to inject their custom handlers and gain control over parsing of the document source code performed when preparing the document for display in the visual editor (at the time of loading the document or switching from the source code to the visual mode).
The visual editor API functions enables you to install parsers of the following three types, with which you can efficiently handle documents before they are passed over to the visual editor:Processes documents at the source code level. To add a content parser:
The handler function (which is essentially the parser itself) must be visible within the scope of addContentParser. The only argument that the function accepts is the document source code. The function processes the code and returns an altered version of it. Otherwise, false can be returned which indicates that no changes are made to the input code.
To install your parser, call oBXEditorUtils.addContentParser.
<script> function CustomContentParser(str) { //... some changes here return str; } // Add the parser oBXEditorUtils.addContentParser(CustomContentParser); </script>
Being installed, this parser allows to process PHP islands in the document source code.
When a document is processed, the system passes code portions to all the installed parsers subsequently, in the form of text string. If a parser returns the code unchanged (the system uses case-sensitive comparison) or returns false, the string is passed to the next registered parser. When installing the parser, you can specify its position in the parser queue. However, the built-in parsers of the visual editor have the highest priority and are called in the first turn. To add a content parser:
The parser must be visible within the scope of addContentParser. The only argument that the function accepts is the source code. The function processes the code and returns an altered version of it. Otherwise, false can be returned which indicates that no changes are made to the input code.
You can use helper methods of oBXEditorUtils.PHPParser to create faster and more efficient parsers.
To install your parser, call oBXEditorUtils.addPHPParser.
<script> function CustomPHPParser(str) { //... handle the document code return str; } //Add handler oBXEditorUtils.addPHPParser(CustomPHPParser); </script>
You must ensure that your content and PHP parsers perform correctly and do no damage to the source code. Otherwise, the visual editor may function improperly.
To add a content parser:
The parser must be visible within the scope of addDOMHandler. The function accepts the document object on input. The function can inspect and alter the document DOM as required. Return values are ignored.
To install your parser, call oBXEditorUtils.addDOMHandler.
<script> function CustomDOMHandler(oDocument) { //... handle the document } //Install parser oBXEditorUtils.addDOMHandler(CustomDOMHandler); </script>
© 2001-2007 Bitrix | Bitrix Site Manager |