administrators (intermediate)
Introduction
PmWiki’s markup translation engine is handled by a set of rules; each rule searches for a specific pattern in the markup text and replaces it with some replacement text. Internally, this is accomplished by using PHP’s “[
Other common examples
Define a custom markup to produce a specific HTML or Javascript sequence
Suppose an admin wants to have a simple “(:example:)” markup that will always produce a fixed HTML string in the output, such as for a webring, Google AdSense display, or Javascript. The Markup() call to do this would be:
Markup('example', 'directives',
'/\\(:example:\\)/',
Keep("<div class='example'><p>Here is a
<a target='_blank' href='http://www.example.com'>link</a> to
<em>example.com</em></p></div>") );
- The first argument is a unique name for the markup (“example”).
- The second argument says to perform this markup along with other directives.
- The third argument is the pattern to look for “(:example:)”.
- The fourth argument is the HTML that “(:example:)” is to be replaced with. We use the Keep() function here to prevent the output from being further processed by PmWiki’s markup rule — in the above example, we don’t want the http://www.example.com url to be again converted to a link.
Define a markup to call a custom function that returns content
An ‘e’ option on the $pattern parameter will cause the $replace parameter to be treated as a PHP expression to be evaluated instead of replacement text. Thus, a markup to produce a random number between 1 and 100 might look like:
Markup('random', 'directives',
'/\\(:random:\\)/e',
"rand(1, 10)");
Arguments can also be passed by using regular expression capturing parentheses, thus
Markup('randomargs', 'directives',
'/\\(:random (\\d+) (\\d+):\\)/e',
"rand('$1', '$2')");
will cause the markup (:random 50 100:) to generate a random number between 50 and 100.
For a PmWiki function to help with parsing arbitrary sequences of arguments and key=value pairs, see Cookbook:ParseArgs.
« Custom InterMap | Documentation Index | Custom WikiStyles »
Q How can I embed JavaScript into a page’s output?
A There are several ways to do this. The Cookbook:JavaScript recipe describes a simple means for embedding static JavaScript into web pages using custom markup. For editing JavaScript directly in wiki pages (which can pose various security risks), see the [
)JavaScript-Editable]] recipe. For JavaScript that is to appear in headers or footers of pages, the [[skin(s
] template can be modified directly, or <script> statements can be inserted using the $HTMLHeaderFmt array.

