This link has been bookmarked by 2 people . It was first bookmarked on 20 Sep 2006, by Mike.
-
30 Apr 08
-
20 Sep 06
-
- 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.
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>") );Define a markup to call a custom function that returns content
An 'e' option on the
$patternparameter will cause the$replaceparameter 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)");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 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: 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.
<< Custom InterMap | Documentation Index | Custom WikiStyles >>
How can I embed JavaScript into a page's output?
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 template can be modified directly, or <script> statements can be inserted using the
$HTMLHeaderFmtarray.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.