12345678910 |
- version=pmwiki-0.6.7
- newline=²
- text=Since a few people have asked, here's a brief summary of the $DoubleBrackets, $LinkPatterns, and $InlineReplacements arrays and how they work/interact. These arrays were designed to allow {{WikiAdministrator}}s to create custom markups without having to modify ''pmwiki.php'' to achieve them. Here's a brief description of the variables:²²$DoubleBrackets contains the substitutions to make before making WikiWord, URL, and other "link" substitutions. It generally handles the conversions of things like [="[[$Group]]", "[[$Title]]", "[[spacewikiwords]]", "[[$LastModified]]"=], etc., which is how it got its name.²²$LinkPatterns specifies the rules for converting {{WikiWord}}s, FreeLinks, [=URLs=], InterMap links, etc. into HTML. ²²$InlineReplacements specifies the substitutions to make after most of the other structural markup has been handled. These include things such as bold/italic text, character entitites, larger/smaller text, and horizontal rules.²²The sequence PmWiki uses to convert wiki markup to HTML approximates something like the following:²²# process any [=[[include:]]=] directives that may exist²# handle any substitutions in $BrowseDirectives²# replace HTML special characters [=(&, <, >) with entities (& < >)=]²# save all text inside of [=[=...=]=] so it doesn't get processed²# process replacements listed in [=$DoubleBrackets=]²# convert sequences matching [=$LinkPatterns=] to HTML and save for step 8²# output "structural" HTML for paragraphs, tables, preformatted text, lists, headers, etc.²# convert replacements given in [=$InlineReplacements=]²# restore the HTML links produced from step 5²# process and apply WikiStyles²# restore the things in [=[=...=]=] from step 2²²Thus, $DoubleReplacements specifies translations to be performed before doing any processing of things held in the $LinkPatterns array, and $InlineReplacements specifies the conversions to be made to handle "inline" sorts of markup after $LinkPatterns and structural markup are done.²²The entries in $DoubleBrackets are associative arrays; the keys (indexes) are replaced by their corresponding values. Thus²² [=$DoubleBrackets["[[Pm]]"] = "[[PatrickMichaud Pm]]";=]²²will replace all occurrences of [="[[Pm]]"=] in the markup with ²[="[[PatrickMichaud Pm]]"=]. This takes place before [=LinkPatterns=] are processed, so the text after substitution will be treated as if the user had entered it directly. Also, the values from [=$DoubleBrackets=] are processed using [=FmtPageName=], so things like '[=$Group', '$Titlespaced', '$PageUrl'=], etc. are replaced with their appropriate values for the page being processed.²²The entries in $InlineReplacements are associative arrays; the keys are regular expressions to be matched, and the values are the replacement strings (via PHP's preg_replace function). ² [=² #### superscripts via ^^text^^, subscripts via __text__² $InlineReplacements['/\\^\\^(.*?)\\^\\^/'] = "<sup>\$1</sup>";² $InlineReplacements['/__(.*?)__/'] = "<sub>\$1</sub>";²² #### a simple smiley to gif conversion² $InlineReplacements['/:-)/'] = ² '<img src="http://www.example.com/smileys/happy.gif" alt=":-)">';=]²²Note that the $InlineReplacement keys must include regular expression delimiters (normally slashes). Also note that the smiley example could not have been done using $DoubleBrackets because the src="[=http://...=]" would've been picked up and modified by the $LinkPatterns.²²The $DoubleBrackets array will also perform a regular expression search/replace (via preg_replace) for any keys that begin with a slash.²²Finally, $LinkPatterns works a bit like $DoubleBrackets and $InlineReplacements, but is more complex because of the variety of replacements to be performed and the fact that order is very significant. The first index of $LinkPatterns entries specifies the sequence in which to process the patterns, the second index specifies the regular expression pattern to match, and the value of the entry specifies either the replacement string or the name of a function to be called to provide the replacement string. Thus:² [=² $LinkPatterns[200]["\\bmailto:($UrlPathPattern)"] = ² "<a href='$0'>$1</a>";=]²²says to replace the markup text like [="mailto:someone@example.com" ²with "<a href='mailto:someone@example.com'>someone@example.com</a>",=]²and to do this after $LinkPatterns numbered less than 200 but before $LinkPatterns numbered higher than 200. The statement² [=² $LinkPatterns[120]["\\bAttach:($UploadNamePattern)"] ² = 'FmtAttachLink';=]²²says to replace Attach: markup by calling the [=FmtAttachLink=] function.²²The standard sequence of replacements in a PmWiki distribution are currently:² [=² 100 ThisWiki:, ThisGroup:, ThisPage: links (from thiswiki.php)² 120 Attach: links (from upload.php)² 200 mailto: links² 300 http:, ftp:, gopher:, etc. links² 400 InterMap links² 500 Group/{{free links}} and Group.{{free links}}² 600 {{free links}}² 700 Group/WikiWords and Group.WikiWords² 800 WikiWords=]²²Note that unlike $InlineReplacements, the regexps in $LinkPatterns cannot include the regular expression delimiters. ²²Anyway, hopefully this sheds a little light on the role that these arrays play in PmWiki's markup to HTML conversion for those who are wanting to add their own customized markups. Of course, if²anyone has any questions, feel free to write me or the listserv.²²%trail%<<|PmWiki.DocumentationIndex|>>
- time=1078362209
- host=24.1.44.14
- agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
- rev=28
- post= Save
- author=Pm
- name=PmWiki.CustomMarkup
|