Test Tokens

Tokens are the basic building blocks of test expressions. See The test and if:test Attributes for information on how test expressions and test tokens are evaluated.

Tokens can be any string of non-whitespace text characters excluding commas (U+002C) and exclamation points (U+0021). For consistency, tokens should consist of a token scheme and a token value, separated by a colon (U+003A).

Processing tools can define any arbitrary tokens or token schemes, or allow users to define tokens or token schemes. To avoid conflicts, token schemes not defined on projectmallard.org should contain a hyphen (U+002D).

Some token schemes may require processing tools to dynamically compute a list of defined tokens.

Target Tokens

Target tokens start with target:. They identify the target environment where the user is reading the content. This may not be the same as the environment the user is reading the content for. For example, a user might use an e-book reader to read help for a desktop operating system.

The following table lists some common target tokens. Processing tools may support tokens not in this list.

Token

Description

target:html

The content has been converted to an HTML document for reading. This token should be true for any version or serialization of HTML, including for XHTML.

target:xhtml

The content has been converted to an XHTML document for reading. To test for a non-XML serialization of HTML, use the test expression target:html !target:xhtml.

target:epub

The content has been converted to an EPUB document for reading.

target:pdf

The content has been converted to a PDF document for reading.

target:mobile

The content is being read on a mobile device, such as a smart phone. Processing tools may use heuristics for this token, such as querying the width of the content area.

target:braille

The content is being read on a braille device.

target:speech

The content is being read aloud, such as by a text-to-speech program.

target:print

The content will be printed. This target may be defined when converting to a print-oriented format, such as PDF.

target:text

The content is being shown in a medium that does not support images or video, such as in a text terminal.

Platform Tokens

Platform tokens start with platform:. They identify the platform that the content is relevant to. They may identify hardware devices, operating systems, desktop environments, or any other aspect of the computing environment that affects the content.

Processing tools may define any platform tokens. The following table lists some example tokens that may be used.

Token

Description

platform:linux

The content applies to operating systems running the Linux kernel.

platform:gnome-shell

The content applies when running GNOME Shell, the core of GNOME 3.

platform:x86

The content applies to CPUs using an x86 architecture.

platform:touch

The content applies for touchscreen devices, such as tablets.

Feature Tokens

Feature tokens start with mallard:. They identify Mallard features supported by the procesing tool. Versions of the core Mallard spec are identified by using the version number as the token value. Extensions are identified by using the extension prefix and version, separated by a slash (U+002F). These values are exactly the same as the version tokens using by the Mallard version attribute.

Some extensions may define more granular feature tokens, to identify particular sets of functionality defined by the extension. These use the base feature token of the extension followed by a hash character (U+0023) and an additional string. These tokens will be listed in the individual extension specifications.

The following table lists some example feature tokens.

Token

Description

mallard:1.0

The processing tool supports Mallard version 1.0.

mallard:if/1.0

The processing tool supports version 1.0 of the Mallard Conditionals extension.

mallard:example/1.1#feature

The processing tool supports the feature feature defined in version 1.1 of the extension example.

Action Tokens

Action tokens start with action:. They identify action schemes for the action attribute supported by the processing tool. For example, if the processing tool supports an install: action scheme, then it should define the test token action:install.

Language Tokens

Language tokens start with lang:. They test the language of the element in the document. A language token is compared against the context language of the element the test condition is on. The context language is the value of the xml:lang attribute on the element, or if the element does not have an xml:lang attribute, the value of the xml:lang attribute on the nearest ancestor element which does.

A language token is true if the context language is the same as the token value, or if the context language is a sublanguage of the token value. All comparisons are case-insensitive. This is equivalent to the XPath lang function.

As a special case for interoperability with POSIX locale identifiers, the token lang:C (or, equivalently, lang:c) is true if there is no xml:lang attribute on the element or any of its ancestor elements.

© 2012 Shaun McCance
cc-by-sa 3.0 (us)

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

As a special exception, the copyright holders give you permission to copy, modify, and distribute the example code contained in this document under the terms of your choosing, without restriction.

Powered by
Mallard