Deprecated: function_exists(): Passing null to parameter #1 ($function) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1309 Deprecated: function_exists(): Passing null to parameter #1 ($function) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1309 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1634 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1634 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1634 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1633 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1634 |
Deprecated: function_exists(): Passing null to parameter #1 ($function) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1309 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 460 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1475 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/astro/public_html/pmwiki/scripts/wikistyles.php on line 130 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1633 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/astro/public_html/pmwiki/pmwiki.php on line 1634 PmWiki /
Custom Markupadministrators (intermediate)
Pm Wiki'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 "preg_replace" function. IntroductionRules are added to the translation engine via Pm Wiki's Markup() or function, which look like Markup($name, $when, $pattern, $replace); # if no evaluation is needed, or if PHP < 5.5 Markup($name, $when, $pattern, $replace_function); # if evaluation is needed # DEPRECATED, will not work as of PHP 7.2 Markup_e($name, $when, $pattern, $replace); # if evaluation is needed and 5.5<=PHP<=7.1
For example, here's the code that creates the rule for Markup("em", "inline", "/''(.*?)''/", "<em>$1</em>");
Basically this statement says to create a rule called "em" to be performed with the other "inline" markups, and the rule replaces any text inside two pairs of single quotes with the same text ($1) surrounded by Sequence in which rules are appliedThe first two parameters to Markup() are used to specify the sequence in which rules should be applied. The first parameter provides a name for a rule -- " The second parameter says that this rule is to be done along with the other "inline" markups. Pm Wiki divides the translation process into a number of phases: _begin start of translation {$var} Page Text Variables happen here. fulltext translations to be performed on the full text split conversion of the full markup text into lines to be processed directives directive processing inline inline markups links conversion of links, url-links, and Wiki Words block block markups style style handling _end end of translation This argument is normally specified as a left-angle bracket ("before") or a right-angle bracket ("after") followed by the name of another rule. Thus, specifying "inline" for the second parameter says that this rule should be applied when the other "inline" rules are being performed. If we want a rule to be performed with the directives -- i.e., before inline rules are processed, we would specify "directives" or "<inline" for the second parameter. {$var} and (:if ...:) conditionalsA significant rule in terms of ordering is "{$var}" which substitutes variables -- if you say "<{$var}" then your markup will be processed before variables are substituted whereas if you say ">{$var}" then your markup will be processed after variables are substituted. This happens before conditional (:if...:) expressions, which is why page text variables are processed even if they are defined inside (:if false:). Markup regular expression definitionThe third parameter is a Perl-compatible regular expression. Basically, it is a slash, a regular expression, another slash, and a set of optional modifiers. The example uses the pattern string Replacement textThe fourth parameter is the replacement text that should be inserted instead of the marked-up wikitext. You can use In the example, we have Here's a rule for Markup("@@", "inline", "/@@(.*?)@@/", "<code>$1</code>");
and for a Markup("comment", "directives", "/\\[:comment .*?:\\]/", '');
Okay, now how about the rule for Markup("strong", "<em", "/'''(.*?)'''/", "<strong>$1</strong>");
This creates a rule called "strong", and the second parameter "<em" says to be sure that this rule is processed before the "em" rule we defined above. If we wanted to do something after the "em" rule, we would use ">em" instead. Thus, it's possible to add rules at any point in Pm Wiki's markup translation process in an extensible manner. (In fact, the "inline", "block", "directives", etc., phases above are just placeholder rules used to provide an overall sequence for other rules. Thus one can use "<inline" to specify rules that should be handled before any other inline rules.) If you want to disable available markup just call e.g.: DisableMarkup("strong");
Pm Wiki's default markup rules are defined in the scripts/stdmarkup.php file. To see the entire translation table as the program is running, the scripts/diag.php module adds " Other common examplesDefine a custom markup to produce a specific HTML or Javascript sequenceSuppose an admin wants to have a simple " 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 The /e modifier has been deprecated and should not be used in ongoing development. See below for more details.
For older PHP versions (< 7.2) an 'e' option on the Markup('random', 'directives', '/\\(:random:\\)/', "MyRandomFunction"); function MyRandomFunction() { return 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 file or in Cookbook recipes. Arguments can also be passed by using regular expression capturing parentheses, thus Markup('randomargs', 'directives', '/\\(:random (\\d+) (\\d+):\\)/', "MyRandomFunction"); function MyRandomFunction($m) { return rand($m[1], $m[2]); } will cause the markup Note: the /e modifier in regular expressions is deprecated since PHP version 5.5, and removed since PHP version 7. The reason for this is, that malicious authors could pass strings that could cause arbitrary and undesirable PHP functions to be executed.
For a Pm Wiki function to help with parsing arbitrary sequences of arguments and key=value pairs, see Cookbook:ParseArgs. Migration to PHP 5.5 and
|