CoLT Custom Formats
« Back to the CoLT Information Page
CoLT allows users to create custom formats to be used when copying a link location and its text. These custom formats also apply to copying the current page location and page title. These two scenarios are called contexts. For the sake of this discussion, we’ll call the first scenario a Link Context, and the second a Page Context. Depending on which context is being used, the available variables have different meanings.
Note that these custom formats all use a percent (%) sign as the first character. If you want an explicit percent embedded in your custom format output, you can do so by using either %% or \%.
Link Context
Copying a link’s location and its text together is considered our link context. Let us work with the following example link:
With our sample link, the following variables are available, and represent the following values:
| Variable | Description | Example Value |
|---|---|---|
| %T | Link text | A Link to Google |
| %U | Link location | http://www.google.com/ |
| %I | Link title attribute text | This is the Title Attribute Text |
| %P | Current page title | Born Geek » CoLT Custom Formats |
| %R | Current page URL | http://www.borngeek.com/firefox/colt/custom-formats/ |
| %S | Not used in link context | — |
| %L | Local time | (localized time stamp) |
| %N | New line character | (new line) |
| %B | Tab character | (tab) |
Page Context
When copying the current page location and title, the available variables change meaning. Using this page as our working example, let’s take a look at what each variable means:
| Variable | Description | Example Value |
|---|---|---|
| %T | Page title | Born Geek » CoLT Custom Formats |
| %U | Page location | http://www.borngeek.com/firefox/colt/custom-formats/ |
| %I | Not used in page context | — |
| %P | Not used in page context | — |
| %R | Not used in page context | — |
| %S | Selected text | (any currently selected text) |
| %L | Local time | (localized time stamp) |
| %N | New line character | (new line) |
| %B | Tab character | (tab) |
Conditional Statements
Beginning with CoLT 2.6.0, conditional statements may now be used in custom formats. The %?[] variable is how these statements are specified, and a particular syntax is expected. Let’s take a look at several examples of how these can be used in practice.
- Simple Conditionals
- A simple conditional statement looks like the following:
%?[S]. In this example, we’re essentially testing the%Svariable (which, if you recall, refers to selected text in a page context). If the user has selected any text (i.e. the%Svariable has a value), its contents will be inserted in the custom format. Otherwise, no text is inserted. - Chaining Simple Conditionals
- Simple conditionals can be chained together, as shown in this example:
%?[S|T]. Here, we have two variables to test:%Sand%T. Variables are always tested from left to right, are always separated by the pipe (|) character, and the first one that has a non-empty value is the one used. In the example I’ve just shown, if the user has selected any text, that selected text will be inserted into the custom format, and the subsequent%T(page title) variable will be ignored. However, if no selected text was present, the%Tvariable will be tested. If it has a non-empty value (and it almost always will), its value will be used instead. If for some reason it also doesn’t have a value, no text will be inserted. - Conditionals Containing Optional Text
- Expanding out from simple conditionals, we can use additional syntax to specify any optional text we want inserted based on the value of a variable. Here’s an example:
%?[S{--- %S ---}]. In this example, if the%Svariable has a non-empty value, the text between the curly braces,--- %S ---, will be inserted in the custom format (with the embedded%Svariable expanded, of course). This usage makes it very easy to include optional text for items like a link’s title text, which may not always be available. - Chaining Optional Text Conditionals
- As you might expect, conditionals with optional text can be chained together:
%?[S{--- %S ---}|T{=== %T ===}]. Armed with the knowledge from above, you should be able to figure out what the result of this custom format would be given whether or not any text was selected.
Here are a couple examples of actual custom formats showing how conditional statements can be used:
<a href="%U">%?[S|T]</a>
This example demonstrates an HTML-style link whose text will either be set to any selected text, or to the link’s text or page title.%T - %U%?[I{ (%I)}]
This example will append a link’s title text (wrapped in parentheses) to the default plain text format, if any title-text is present. Otherwise, the plain text format is all that gets copied.
