Attention

This document was written for an unsupported version of Plone, Plone 2.1.x, and was last updated 1240 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Introduction

by Martin Aspeli last modified Dec 30, 2008 03:05 PM
Background on MIME types, MimetypesRegistry and PortalTransforms

MIME types are classifications of content, typically used for email attachments and other places where data is interchanged and must be described. For example, the 'text/html' type represents HTML content, whilst the 'text/structured' type represents StructuredText. The 'MimetypesRegistry', bundled with Archetypes, keeps track of the various MIME types available to Plone in the 'mimetypes_registry' tool.

'PortalTransforms', also bundled with Archetypes, provides the 'portal_transforms' tool, which is used to transform data between two MIME types. For example, if you enter StructuredText in a Page, it is transformed to HTML via the 'st' transform when the object is displayed.

In this tutorial, you will learn how to register new MIME types with 'mimetypes_tool', and how to create new transforms with 'PortalTransforms'. The example used throughout the tutorial is the 'intelligenttext' product, "found in the Collective":https://svn.plone.org/svn/collective/intelligenttext/trunk. This provides a new MIME type, 'text/x-web-intelligent', which describes a plain text type that can be transformed to HTML in such a way that paragraph breaks and indentation remains, and web- and email addresses become clickable links. The transform that converts from 'text/x-web-intelligent' to 'text/html' is called 'web_intelligent_plain_text_to_html'.

Additionally, the product provides a 'html_to_web_intelligent_plain_text' transform that can convert HTML to plain text. Note that these transforms are not commutative, so if you convert from 'text/x-web-intelligent' to 'text/html' and then back to 'text/x-web-intelligent', you may not end up with exactly what you started with. This is because HTML is much richer than plain text in formatting, and certain assumptions are made about how to sensibly represent various HTML tags and entities as plain text.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.