2

假设我想创建标记来转换它:

Some text. SHOUTY Hello. Some more text.

进入这个:

Some text. HELLO! Some more text.

我会用下面的 PHP 做到这一点:

Markup('SHOUTY', 'directives',
  '/SHOUTY\\s*(.+?)\\./gs',
  'MarkupSHOUTY');

function MarkupSHOUTY($matches) {
  return mb_strtoupper($matches[1]) . '!';
}

这适用于上面的幼稚测试用例,但在实际使用中失败:

This is SHOUTY Sparta.

SHOUTY He took his vorpal sword in hand:
Long time the manxome foe he sought --
So rested he by the Tumtum tree,
And stood awhile in thought.

Don't press the button. SHOUTY Don't press it.

变成

This is SPARTA!

SHOUTY He took his vorpal sword in hand:
Long time the manxome foe he sought --
So rested he by the Tumtum tree,
And stood awhile in thought.

Don't press the button. DON'T PRESS IT!

如何在 PmWiki 中创建多行标记?

4

1 回答 1

1

正如您已经猜到的,PmWiki 的标记到 html 转换是一个多阶段的过程,包括应用一组有序的正则表达式匹配和文本替换。

一些理论考虑

Markup($name, $when, $pattern, $replace)函数 (in pmwiki.php) 负责定义转换管道本身并使用预定义规则 (in )stdmarkup.php和您可能在Local Configuration Files中提供的您自己的规则来填充它。

定义标记文档页面将预定义阶段描述为:

_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 WikiWords     
block       block markups
style       style handling       
_end        end of translation

根据函数文档,Markup()参数定义为:

$name

字符串命名插入的规则。如果已存在同名规则,则忽略此规则。

$when

此字符串用于控制相对于其他规则何时应用规则。一个规范"<xyz"说在命名规则之前应用这个规则"xyz",而在">xyz"规则之后应用这个规则"xyz"。有关规则顺序的更多详细信息,请参阅CustomMarkup

$pattern

此字符串是翻译引擎用来在标记源中查找此规则的出现的正则表达式。

$replace

当匹配发生时,此字符串将替换匹配的文本,或者将返回替换文本的函数名称。

将此应用于您的案例

指定"directives"$when占位符会导致标记规则在文本已被分割成行后应用于文本。

因此,为了发生在多行上,应该在分行之前进行指令工作,例如:

Markup('SHOUTY', '<split',
  '/SHOUTY\\s*(.+?)\\./gs',
  'MarkupSHOUTY');
于 2018-03-07T14:12:54.030 回答