- 追加された行はこの色です。
- 削除された行はこの色です。
#freeze
TITLE:ネイティブエイリアス
#indent
#contents
////////////////////////////////////////////////////////////////
*方針 [#h52cece1]
「##&';&';〜&';&';##」や「##&';&';&';〜&';&';&';##」のような、同じ記号を2文字または3文字使って修飾部を挟む書式は Wiki の代表的な書式である。
ネコヰキではこれをネイティブ書式と呼ぶ。
一方、PukiWikiでは「##&&;〜;##」や「##&#;〜;##」などのプラグインを導入することにより機能拡張を容易にした。サ行変格活用の如く、書式としては例外的ではあるが、用例の数は断然多い。ネコヰキではこれをプラグイン書式と呼ぶ。
プラグイン書式の弱点は、開始記号と終了記号が「##&';&';〜&';&';##」のように同じでもなければ、「##&(;&(;〜&);&);##」のように対にもなってないこと、そしてプラグイン名はテキストであるため文書に埋もれやすいことである。
このため、良く使うプラグインはネイティブ書式にしたい。
ここで、プラグインのエイリアスとしてネイティブ書式を扱うため、このような書式をネイティブエイリアスと呼ぶことにする。
ネコヰキの性質上、当面は数式とコードの2つのプラグインのネイティブエイリアスのみを導入する。
書式は、2文字と3文字でインラインプラグインとブロックプラグインを使い分ける。
引数の展開/保持は対応するプラグイン書式に準ずる。
* 仕様 [#q38acc3a]
書式文字を「##@##」、対応するプラグイン名を「##plugin##」とする。
:単一行インラインプラグイン|「##@@〜@@##」は「##&plugin(〜);##」または「##&plugin{〜};##」と等価である。
機能的違いは引数の展開/保持。どっちになるかはプラグインの性質次第。
:複数行インラインプラグイン|
^@@ …
^〜
^@@
は
^$plugin(…){{{{{{{{{{{{{{{{
^〜
^}}}}}}}}}}}}}}}};
と等価である。
:複数行ブロックプラグイン|
^@@@ …
^〜
^@@@
は
^#plugin(…){{{{{{{{{{{{{{{{
^〜
^}}}}}}}}}}}}}}}}
と等価である。
数式プラグインの場合、書式文字は「##$##」、プラグイン名は「##eq##」。
書式文字は TeX のインライン数式モード「##$〜$##」に由来。
用例は[[書式/数式]]を参照。
コードプラグインの場合、書式文字は「##&#;##」、プラグイン名は「##code##」。
書式文字は、「#####」の形が等幅表示のための桝目からの連想。
また、C言語で、別言語であるプリプロセッサのコードを埋め込むときに用いられることからの連想。
用例は[[書式/コード]]を参照。
* 実装 [#g668057c]
** 単一行インラインプラグイン [#y4dab69e]
- ##lib/make_link.php## の ##class InlineConverter## の ##function InlineConverter## にて、
#code(diff){{{{
function InlineConverter($converters = NULL, $excludes = NULL)
{
if ($converters === NULL) {
$converters = array(
'plugin', // Inline plugins
+ 'eq', // eq plugin
+ 'code', // code plugin
'escape', // Escapes
'note', // Footnotes
……
}}}}
- ##lib/make_link.php## の ##class Link_plugin## の後に以下を追加。
#code(php){{{{
// Native-alias Plugin
class Link_plugin_alias extends Link_plugin
{
var $name = 'echo'; // プラグイン名
var $pattern = ''; // 正規表現 Link_plugin に対応させるため、
// $matches[1] = plain
// $matches[2] = plugin name
// $matches[3] = parameter
// $matches[4] = body // 独自拡張 // 引数展開
function Link_eq($start)
{
parent::Link_plugin($start);
}
function get_pattern()
{
return $this->pattern;
}
function get_count()
{
return 4;
}
function set($arr, $page)
{
list(, $this->plain, , $this->param, $body) = $this->splice($arr);
return parent::setParam($page, $this->name, $body, 'plugin');
}
}
// Native-alias for &eq plugin
class Link_eq extends Link_plugin_alias
{
var $name = 'eq';
var $pattern = '\$\$(()(.+?)())\$\$'; // no name, no body
}
// Native-alias for &code plugin
class Link_code extends Link_plugin_alias
{
var $name = 'code';
var $pattern = '\#\#(()()(.+?))\#\#'; // no name, no parameter
}
}}}}
-- Link_plugin_alias は基底クラス。直接生成されることはない。
-- ##eq## は引数保持、##code## は引数展開。
** 複数行インラインプラグイン [#ueecdb8a]
- ##lib/convert_html.php## の ##class Body## の ##function parse## にて、 複数行プラグインの後あたり。
#code(php){{{{{{{{{{{{{{{{{{{{
// Native-alias for $eq-Plugin
$pattern = '/^\s*\$\$\s*$/';
if (preg_match($pattern, $line)) {
$delimiter = "\r";
$line = '&eq{{{{{{{{{{{{{{{{'.$delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
if ($indent_format)
{
preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
$next_line = $matches[2];
}
if (preg_match($pattern, $next_line)) {
$line .= ltrim('}}}}}}}}}}}}}}}};');
break;
} else {
$line .= $next_line . $delimiter;
}
}
}
}}}}}}}}}}}}}}}}}}}}
#code(diff){{{{{{{{{{{{{{{{{{{{
! // Native-alias for $code-Plugin
! $pattern = '/^\s*##\s*$/';
if (preg_match($pattern, $line)) {
$delimiter = "\r";
! $line = '$code{{{{{{{{{{{{{{{{'.$delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
if ($indent_format)
{
preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
$next_line = $matches[2];
}
if (preg_match($pattern, $next_line)) {
$line .= ltrim('}}}}}}}}}}}}}}}};');
break;
} else {
$line .= $next_line . $delimiter;
}
}
}
}}}}}}}}}}}}}}}}}}}}
-- 「##!##」に行は、##eq##プラグイン に対する ##code## プラグインの差分。
** 複数行ブロックプラグイン [#v78fcaaf]
- ##lib/convert_html.php## の ##class Body## の ##function parse## にて、 複数行プラグインの後あたり。
#code(diff){{{{{{{{{{{{{{{{{{{{
! // Native-alias for #eq-Plugin
! $pattern = '/^\s*\$\$\$\s*$/';
if (preg_match($pattern, $line)) {
$delimiter = "\r";
! $line = '#eq{{{{{{{{{{{{{{{{'.$delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
if ($indent_format)
{
preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
$next_line = $matches[2];
}
if (preg_match($pattern, $next_line)) {
$line .= ltrim('}}}}}}}}}}}}}}}}');
break;
} else {
$line .= $next_line . $delimiter;
}
}
}
}}}}}}}}}}}}}}}}}}}}
#code(diff){{{{{{{{{{{{{{{{{{{{
! // Native-alias for #code-Plugin
! $pattern = '/^\s*###\s*(\w*)\s*$/';
! if (preg_match($pattern, $line, $matches)) {
$delimiter = "\r";
! $line = '#code('.$matches[1].'){{{{{{{{{{{{{{{{'.$delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
if ($indent_format)
{
preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
$next_line = $matches[2];
}
if (preg_match($pattern, $next_line)) {
$line .= ltrim('}}}}}}}}}}}}}}}}');
break;
} else {
$line .= $next_line . $delimiter;
}
}
}
}}}}}}}}}}}}}}}}}}}}
-- 「##!##」に行は、それぞれの複数行インラインプラグインに対する差分。
////////////////////////////////////////////////////////////////
* コメント [#i7262c9c]
#pcomment
////////////////////////////////////////////////////////////////