TransPythia - Transcoding actions

TransPythia uses TranscodingAction to adapt content. This section provides a short description of the existing actions. Although not required, a transcoding action is usually atomic, i.e. it performs one and only one type of content adaptation.

Transcoding actions on HTML content

Images conversion and resizing

Action name

ResizeIMG

Description

Resizes images that appear in the HTML content to match the requesting device's list of supported image formats and screen size. Image formats that are not supported by the requesting device and that cannot be converted to another format are removed. The action also completes the HTML markup as needed to add the width and height attributes of images where missing. The action also tries to further reduce images whose size still exceed a maximum size (10Kb by default) after conversion and removes the images that cannot be reduced appropriately

This action follows the Mobile Web Best Practices on Image Size.

This action is not entirely atomic, i.e. it adapts HTML content to complete, change or remove the img elements it contains, and it also adapts and caches the images so that they may be served to the client that renders the HTML content.

Pop-up windows suppression

Action name

DeletePopup

Description

Removes all pop-up links from the HTML content when the requesting device is identified as mobile. A pop-up is identified as a link with a target="_blank" attribute. Markup elements impacted: a, area, base, form, link.

This action implements the POP_UPS Mobile Web Best Practice (Do not cause pop-ups or other windows to appear and do not change the current window without informing the user).

Code example

// NB: $service and $evidence must have been initialized.
$content = '<a href="example.html" target="_blank">Link</a>';
$action = new TranscodingActionDeletePopup($service);
$content = $action->apply($content, $evidence);
echo $content;

The content remains unchanged for non-mobile devices. The code produces the following output on a mobile device:
<a href="example.html">Link</a>

Scripts suppression

Action name

DeleteScript

Description

Removes all scripts from the HTML content if the requesting device does not support scripting. Scripts may be defined in script elements or as event attributes such as onclick, onmousedown, onchange, ...

This action follows the spirit of the OBJECTS_OR_SCRIPT Mobile Web Best Practice (Do not rely on embedded objects or script). Content should still be usable without scripts!

Code example

// NB: $service and $evidence must have been initialized.
$content = '<head><script src="script.js" type="text/javascript" /></head>';
$action = new TranscodingActionDeleteScript($service);
$content = $action->apply($content, $evidence);
echo $content;

The content remains unchanged when the requesting device supports scripting. The code produces the following output for a device that has no support for scripting:
<head></head>

Embedded elements suppression

Action name

DeleteEmbeds

Description

Removes all embedded elements (applet, embed, iframe) contained in the HTML content when the requesting device is identified as mobile.

This action follows the spirit of the OBJECTS_OR_SCRIPT and NO_FRAMES Mobile Web Best Practices (Do not rely on embedded objects or script and Do not use frames).

Code example

// NB: $service and $evidence must have been initialized.
$content = '<head><script src="script.js" type="text/javascript" /></head>';
$action = new TranscodingActionDeleteScript($service);
$content = $action->apply($content, $evidence);
echo $content;

The content remains unchanged when the requesting device supports scripting. The code produces the following output for a device that has no support for scripting:
<head></head>

Tables linearization

Action name

LinearTables

Description

Linearizes nested tables and tables that are used to control the layout of the page when the requesting device is identified as mobile. Linearizes tables that convey tabular data when the requesting device does not support tables.

This action follows the set of Mobile Web Best Practices around tables.

Code example

// NB: $service and $evidence must have been initialized.
// The following table is used for layout purposes (only two cells!)
$content = '<table><tr><td>Column 1</td><td>Column 2</td></tr></table>';
$action = new TranscodingActionLinearTables($service);
$content = $action->apply($content, $evidence);
echo $content;

The content remains unchanged for devices that are not identified as mobile. The code produces the following output for mobile devices and for devices that do not support tables:
<div>Column 1</div><div>Column 2</div>

HTML entities conversion

Action name

ReplaceEntities

Description

When XHTML content is served as application/xhtml+xml with a mobile DOCTYPE (e.g. the XHTML Basic 1.1 DTD), some non-mobile browsers fail to recognize HTML entities such as &nbsp; or &acute;. This action replaces all the XHTML character entities defined in the XHTML Modularization 1.1 standard by their numeric equivalent. For instance, it replaces &copy; by &#169;.

This action follows the spirit of the DEFICIENCIES Mobile Web Best Practice (Take reasonable steps to work around deficient implementations).

Transcoding actions on other types of content

The following actions should not be mixed with the previous ones as they do not apply to HTML content.

CSS conversion

Action name

CSSAdaptation

Description

Adapts CSS content to improve content layout on mobile devices.

This action follows the spirit of the MEASURES Mobile Web Best Practice (Do not use pixel measures and do not use absolute units in markup language attribute values and style sheet property values).

This action should be regarded as work in progress. Adapting CSS content is not an easy task as support for CSS varies from one device to another. This action should not be used on an automated basis, but may be useful when converting a theme or template of a CMS tool to address mobile-friendliness.

Template switching

Action name

SwitchTemplate

Description

Switches the template to a mobile-friendly template when the requesting device is identified as mobile.

This action does not apply on any particular content. It simply returns the most appropriate theme for the requesting device, and may be used to deploy a desktop-oriented theme and a mobile-oriented theme on the same site when the underlying authoring tool does not provide that functionality.

Contact: François Daoust <fd@w3.org>