KKnd   PmWikiZhCnUtf8 /
CustomMarkup
SearchWiki
PmWikiZhCnUtf8.最近改变
编辑页面
页面修正

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 wiki administrators to create custom markups without having to modify pmwiki.php to achieve them. Here's a brief description of the variables:

因为有一些人问到$DoubleBrackets, $LinkPatterns, 和 $InlineReplacements数组是如何交互和工作的,所以在这里给出一个简单的介绍。这几个数组被设计用来允许一个wiki管理员自定义一些标签而不需要修改pmwiki.php文件。下面是一个这些变量的简单的描述:

$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.

$DoubleBrackets 在进行WikiWord, URL, 和其它链接的替换之前所做的一些替换都包含在$DoubleBrackets中,通常,这个替换功能做诸如"[[$Group]]", "[[$Title]]", "[[spacewikiwords]]", "[[$LastModified]]"等变量的替换工作,即是获得相应的名

$LinkPatterns specifies the rules for converting WikiWords, freelinks, URLs, InterMap links, etc. into HTML.

$LinkPatterns 则是指定WikiWords, freelinks, URLs, InterMap 链接转换为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.

$InlineReplacements 则是在完成大多数结构性标签的处理之后,进行的替换工作,包括诸如黑体/斜体文字,character entitites, 字体大小,和水平分割线。

The sequence PmWiki uses to convert wiki markup to HTML approximates something like the following:

  1. replace HTML special characters (&, <, >) with entities (&amp; &lt; &gt;)
  2. save all text inside of ... so it doesn't get processed
  3. process replacements listed in $DoubleBrackets
  4. convert sequences matching $LinkPatterns to HTML and save for step 8
  5. output "structural" HTML for paragraphs, tables, preformatted text, lists, headers, etc.
  6. convert replacements given in $InlineReplacements
  7. restore the HTML links produced from step 5
  8. process and apply WikiStyles
  9. restore the things in [=...=] from step 2

PmWiki转化wiki标签到相近的HTML的过程大体如下:
  1. 将HTML中的某些特别字符(&, <, >)用相应用的字符代替(&amp; &lt; &gt;)
  2. 保存在[=...=]标签中字符,因为这些字符不用处理。
  3. 完成在列表$DoubleBrackets中的字符替换工作。
  4. 转化与$LinkPatterns列表匹配的序列成相应的HTML并为第8步保存这些链接HTML
  5. 输出结构性的HTML,比如段短,表格,预定义文本,列表,页眉。
  6. 完成在$InlineReplacements列表中的替换工作。
  7. 恢复在第5步保存的HTML链接。
  8. 应用WikiStyles
  9. 恢复在第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:[email protected]" with "<a href='mailto:[email protected]'>[email protected]</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 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.

<< CustomFreeLinks | PmWikiZhCnUtf8.DocumentationIndex | Upgrades >>


编辑页面 - 页面修正 - WikiHelp - SearchWiki - 最近改变 - Printable Version
页面最后更新于 17 九月, 2003, 时间 22:23

©
copyleft by [email protected]
or
[email protected]