HTML exporter
From AbiWiki
Line 4: | Line 4: | ||
To reduce dependencies between different parts of HTML plugin it`s functionality was split into several parts - Abiword document contents recognition( sections, blocks, etc) and translation into form, that is suitable to generate tags, tag generation, CSS generation and exporting data items. | To reduce dependencies between different parts of HTML plugin it`s functionality was split into several parts - Abiword document contents recognition( sections, blocks, etc) and translation into form, that is suitable to generate tags, tag generation, CSS generation and exporting data items. | ||
==Abiword document contents recognition and translation== | ==Abiword document contents recognition and translation== | ||
+ | To explore contents of the document being exported PL_Listener should be used. But to make exporting document to some XML/HTML based file format we need to take in account that listener won`t notify us if some block of document is ended - it will only tell that new block started. In case if need to close some tags if we are leaving some block/section it`s little uncomfortable. So to make exporting process little easier two classes were developed - IE_Exp_HTML_Listener and IE_Exp_HTML_ListenerImpl (such methodic is used in opendocument plugin). | ||
+ | ===IE_Exp_HTML_ListenerImpl=== | ||
+ | This class should be used as a base class if we want to implement exporting to HTML/XHTML. It contains set of all needed methods to generate correct HTML/XHTML document. All it`s methods are virtual and by default do nothing. So derived class just need to override them. | ||
+ | ===IE_Exp_HTML_Listener=== | ||
+ | This class inheriths PL_Listener and translates it`s calls to instance of IE_Exp_HTML_ListenerImpl, so correct document can be generated. E.g. if IE_Exp_HTML_Listener found a document block - it calls IE_Exp_HTML_ListenerImpl::openBlock and then, when end of the block is riched - IE_Exp_HTML_ListenerImpl::closeBlock. | ||
+ | ==Tag generation== | ||
+ | To generate tags for the exported document set of utility classes were developed. Because HTML exporter supports both simple HTML/XHTML and multipart documents (MHT), interface for output was created - it`s abstract class OutputWriter that declare`s only one method - *write*. This interface is implemented by two derived classes - IE_Exp_FileWriter( for normal document export to filesystem) and IE_Exp_StringWriter (for exporting document into MHT archive). | ||
+ | To generate tags IE_Exp_HTML_TagWriter class should be used. It contains most of the methods that are needed to generate HTML/XML tags - it supports generating pair and single tags, adding attributes, data and comments. Also, code that produced by IE_Exp_HTML_TagWriter is aligned according to document structure. |
Revision as of 03:55, 19 August 2011
HTML plugin allows Abiword users to export their documents to such file formats as HTML and XHTML. It supports several exportin goptions that customize contents of the generated document. Because this plugin is being developed for a long time and every it`s part become to tightly connected with each other(In fact generation of tags, css, saving images and listening to Abiword document contents were located in one big class called s_HTML_Listener), plugin`s code refactoring was done.
Contents |
HTML plugin structure
To reduce dependencies between different parts of HTML plugin it`s functionality was split into several parts - Abiword document contents recognition( sections, blocks, etc) and translation into form, that is suitable to generate tags, tag generation, CSS generation and exporting data items.
Abiword document contents recognition and translation
To explore contents of the document being exported PL_Listener should be used. But to make exporting document to some XML/HTML based file format we need to take in account that listener won`t notify us if some block of document is ended - it will only tell that new block started. In case if need to close some tags if we are leaving some block/section it`s little uncomfortable. So to make exporting process little easier two classes were developed - IE_Exp_HTML_Listener and IE_Exp_HTML_ListenerImpl (such methodic is used in opendocument plugin).
IE_Exp_HTML_ListenerImpl
This class should be used as a base class if we want to implement exporting to HTML/XHTML. It contains set of all needed methods to generate correct HTML/XHTML document. All it`s methods are virtual and by default do nothing. So derived class just need to override them.
IE_Exp_HTML_Listener
This class inheriths PL_Listener and translates it`s calls to instance of IE_Exp_HTML_ListenerImpl, so correct document can be generated. E.g. if IE_Exp_HTML_Listener found a document block - it calls IE_Exp_HTML_ListenerImpl::openBlock and then, when end of the block is riched - IE_Exp_HTML_ListenerImpl::closeBlock.
Tag generation
To generate tags for the exported document set of utility classes were developed. Because HTML exporter supports both simple HTML/XHTML and multipart documents (MHT), interface for output was created - it`s abstract class OutputWriter that declare`s only one method - *write*. This interface is implemented by two derived classes - IE_Exp_FileWriter( for normal document export to filesystem) and IE_Exp_StringWriter (for exporting document into MHT archive). To generate tags IE_Exp_HTML_TagWriter class should be used. It contains most of the methods that are needed to generate HTML/XML tags - it supports generating pair and single tags, adding attributes, data and comments. Also, code that produced by IE_Exp_HTML_TagWriter is aligned according to document structure.