Here is a
link to
example.com
") );
@]
* 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.
[[#random]]
!!! 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, 100)");
@]
This calls the PHP built-in rand() function and substitutes the directive with the result. Any function can be called, including functions defined in a [[local customization(s)]] file.
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.
->%note% Note: Be very careful with the /e modifier in regular expressions; malicious authors may be able to pass strings that cause arbitrary and undesirable PHP functions to be executed.
For a PmWiki function to help with parsing arbitrary sequences of arguments and key=value pairs, see Cookbook:ParseArgs.
>>faq<< [[#faq]]
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 [[(Cookbook:)JavaScript-Editable]] recipe. For JavaScript that is to appear in headers or footers of pages, the [[skin(s)]] template can be modified directly, or