Mientras no se diga lo contrario: |
PmWiki /
CustomMarkupadministrators (intermediate) IntroductionPmWiki'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. Rules are added to the translation engine via PmWiki's Markup() function, which looks like Markup($name, $when, $pattern, $replace);
where 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 The 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. PmWiki divides the translation process into a number of phases: _begin start of translation 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 WikiWords block block markups style style handling _end end of translation 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" for the second parameter. The third parameter is a Perl-compatible regular expression. Basically, it is a slash, a regular expression, another slash, and (optionally) a set of options ("modifiers"). The example uses the pattern string The fourth parameter is the replacement text that should be inserted instead of the marked-up wikitext. You can use In the example, we have ExamplesHere'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 PmWiki'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.: Markup("strong", "<em");
The lack of a pattern & replacement parameters indicates that you simply wish to disable the markup. PmWiki'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 " More examplesCall a user function which returns some contentAn 'e' option on the The markup (:meeting:) uses this by calling a hypothetical global function meeting() (say, defined in Markup('meeting', 'directives', '/\\(:meeting:\\)/e', 'meeting()');
Note also, that the 'e' option is a standard Simple macro replacement:Markup('bigP', 'fulltext', '/\{bigP\}/', '%font-size="40px"% P' . '%block font-size="15px" border="0px" ' . 'padding="4px 14px 7px 14px" bgcolor=#FFB% '); This uses the fulltext phase to simply replace the {bigP}ie Jesu Domine, dona eis requiem (''whack''). produces this effect: P ie Jesu Domine, dona eis requiem (whack). Adding an argument (as in Add Google Search to your wikiGerman Example, Same Window Put this text at the bottom of your config.php file Markup('googlesearch', 'directives', '/\\(:googlesearch:\\)/e',"Keep(\" <FORM method=GET action='http://www.google.de/search'> <TABLE><tr><td> <A HREF='http://www.google.de'> <IMG SRC='http://www.google.de/logos/Logo_40wht.gif' border='0' ALT='Google' align='absmiddle'></A> <INPUT TYPE=text name=q size=20 maxlength=255 value=''> <INPUT TYPE=hidden name=hl value=de> <INPUT type=submit name=btnG VALUE='Google Search'> </td></tr></TABLE> </FORM> \")"); Put (:googlesearch:) anywhere on your Page. --newmy Add Google Safe Search in a New Window to your wikiEnglish Example, Safe Search in a New Window Put this text at the bottom of your config.php file Markup('googlesearch', 'directives', '/\\(:googlesearch:\\)/e',"Keep(\" <FORM method=GET action='http://www.google.com/search' target='_blank'> <TABLE><tr><td> Google Safe Search <A HREF='http://www.google.com/search?safe=vss'></A> <INPUT TYPE=text name=q size=42 maxlength=255 value=''> <INPUT type=hidden name=safe value=strict> <INPUT type=submit name=sa value='Google Search'> </td></tr></TABLE> </FORM> \")"); Now you can put (:googlesearch:) anywhere on your Page. --Jeff, Corpus Christi, Texas Add Local Weather to your site Put this text at the bottom of your config.php file Markup('localweather', 'directives', '/\\(:localweather:\\)/e',"Keep(\" <script src='http://voap.weather.com/weather/oap/78410?template=GENXV&par=null&unit=0&key=021c5b063db71b7fdd9a11f5ec88c033'></script> \")"); Now you can put (:localweather:) anywhere on your Page. --Jeff, Corpus Christi, Texas Note: You will need to go to http://www.weather.com to get the script line to replace the script line above. Just place your script between:Markup('localweather', 'directives', '/\\(:localweather:\\)/e',"Keep(\" and \")"); << Custom InterMap | DocumentationIndex | Custom WikiStyles >> |