|
|
|
@ -9,46 +9,54 @@ class Dokuwiki
@@ -9,46 +9,54 @@ class Dokuwiki
|
|
|
|
|
private array $_dictionary = |
|
|
|
|
[ |
|
|
|
|
// Headers |
|
|
|
|
'/^[\s]?#([^#]+)/' => "# $1\n\r", |
|
|
|
|
'/^[\s]?##([^#]+)/' => "## $1\n\r", |
|
|
|
|
'/^[\s]?###([^#]+)/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?####([^#]+)/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?#####([^#]+)/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?######([^#]+)/' => "### $1\n\r", |
|
|
|
|
|
|
|
|
|
'/^[\s]?[=]{6}([^=]+)[=]{6}/' => "# $1\n\r", |
|
|
|
|
'/^[\s]?[=]{5}([^=]+)[=]{5}/' => "## $1\n\r", |
|
|
|
|
'/^[\s]?[=]{4}([^=]+)[=]{4}/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?[=]{3}([^=]+)[=]{3}/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?[=]{2}([^=]+)[=]{2}/' => "### $1\n\r", |
|
|
|
|
'/^[\s]?[=]{1}([^=]+)[=]{1}/' => "### $1\n\r", |
|
|
|
|
'/^([\s]?)#([^#]+)/' => '$1#$2' . PHP_EOL, |
|
|
|
|
'/^([\s]?)##([^#]+)/' => '$1##$2' . PHP_EOL, |
|
|
|
|
'/^([\s]?)###([^#]+)/' => '$1###$2' . PHP_EOL, |
|
|
|
|
'/^([\s]?)####([^#]+)/' => '$1###$2' . PHP_EOL, |
|
|
|
|
'/^([\s]?)#####([^#]+)/' => '$1###$2' . PHP_EOL, |
|
|
|
|
'/^([\s]?)######([^#]+)/' => '$1###$2' . PHP_EOL, |
|
|
|
|
|
|
|
|
|
'/^[\s]?[=]{6}([^=]+)[=]{6}/' => '# $1' . PHP_EOL, |
|
|
|
|
'/^[\s]?[=]{5}([^=]+)[=]{5}/' => '## $1' . PHP_EOL, |
|
|
|
|
'/^[\s]?[=]{4}([^=]+)[=]{4}/' => '### $1' . PHP_EOL, |
|
|
|
|
'/^[\s]?[=]{3}([^=]+)[=]{3}/' => '### $1' . PHP_EOL, |
|
|
|
|
'/^[\s]?[=]{2}([^=]+)[=]{2}/' => '### $1' . PHP_EOL, |
|
|
|
|
'/^[\s]?[=]{1}([^=]+)[=]{1}/' => '### $1' . PHP_EOL, |
|
|
|
|
|
|
|
|
|
// Links |
|
|
|
|
// '/\{\{([^\:]+)\:([^\}\}]+)\}\}/' => "=> /$1 $1\n\r", // @TODO |
|
|
|
|
'/\{\{indexmenu\>\:([^\}\}]+)\}\}/' => "=> /$1 $1\n\r", // @TODO |
|
|
|
|
'/\[\[wp([A-z]{2})\>([^\|]+)\|([^\]\]]+)\]\]/' => "=> https://$1.wikipedia.org/wiki/$2 $3\n\r", |
|
|
|
|
'/\[\[wp\>([^\|]+)\|([^\]\]]+)\]\]/' => "=> https://en.wikipedia.org/wiki/$1 $2\n\r", |
|
|
|
|
'/\[\[([^|]+)\|([^\]\]]+)\]\]/' => "=> $1 $2\n\r", |
|
|
|
|
'/\{\{([^:]+):([^\}]+)\}\}/' => PHP_EOL . '=> $1 $1' . PHP_EOL, // @TODO |
|
|
|
|
'/\{\{indexmenu\>:([^\}]+)\}\}/' => PHP_EOL . '=> $1 $1' . PHP_EOL, // @TODO |
|
|
|
|
'/\[\[wp([A-z]{2})\>([^\|]+)\|([^\]\]]+)\]\]/' => PHP_EOL . '=> https://$1.wikipedia.org/wiki/$2 $3' . PHP_EOL, |
|
|
|
|
'/\[\[wp\>([^\|]+)\|([^\]\]]+)\]\]/' => PHP_EOL . '=> https://en.wikipedia.org/wiki/$1 $2' . PHP_EOL, |
|
|
|
|
'/\[\[([^|]+)\|([^\]\]]+)\]\]/' => PHP_EOL . '=> $1 $2' . PHP_EOL, |
|
|
|
|
|
|
|
|
|
// Tags |
|
|
|
|
'/<code>/' => '```', |
|
|
|
|
'/<\/code>/' => '```', |
|
|
|
|
'/<code>/i' => '```', |
|
|
|
|
'/<\/code>/i' => '```', |
|
|
|
|
'/<wrap[^>]+>([^<]?)/i' => '$1', |
|
|
|
|
'/<\/wrap>/i' => '$1', |
|
|
|
|
|
|
|
|
|
'/<file>/' => '```', |
|
|
|
|
'/<file\s-\s([^>]+)>/' => "$1\n\r" . '```', |
|
|
|
|
'/<\/file>/' => '```', |
|
|
|
|
'/<file>/i' => '```', |
|
|
|
|
'/<file[\s]+-[\s]+([^>]+)>/i' => '$1```', |
|
|
|
|
'/<\/file>/i' => '```', |
|
|
|
|
|
|
|
|
|
'/[*]+([^*]+)[*]+/' => '*$1*', |
|
|
|
|
'/[\'\']+([^\']+)[\'\']+/' => '```$1```', |
|
|
|
|
//'/[*]+([^*]+)[*]+/' => '$1', // @TODO bugged, e.g. crontab tasks |
|
|
|
|
'/\'\'([^\']+)\'\'/' => '$1', |
|
|
|
|
'/%%([^%]+)%%/' => '$1', |
|
|
|
|
'/\/\/^:([^\/]+)\/\//' => '$1', |
|
|
|
|
|
|
|
|
|
// List |
|
|
|
|
'/^-/' => '* ', |
|
|
|
|
'/^[\s]?-/' => '* ', |
|
|
|
|
'/^[\s]+\*/' => '*', |
|
|
|
|
|
|
|
|
|
// Separators |
|
|
|
|
'/[-]+/' => '-', |
|
|
|
|
'/[ ]+/' => ' ', |
|
|
|
|
'/[\\\]+/' => "\n\r", |
|
|
|
|
'/[\n\r]{1,}/' => "\n\r", |
|
|
|
|
'/[\\\]{2}/' => PHP_EOL, |
|
|
|
|
|
|
|
|
|
// Plugins |
|
|
|
|
'/~~DISCUSSION~~/' => '', // @TODO |
|
|
|
|
|
|
|
|
|
// Final corrections |
|
|
|
|
'/[\n\r]+[.,;:]+/' => PHP_EOL |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
public function __construct(?array $dictionary = null) |
|
|
|
@ -85,24 +93,24 @@ class Dokuwiki
@@ -85,24 +93,24 @@ class Dokuwiki
|
|
|
|
|
|
|
|
|
|
foreach ((array) explode(PHP_EOL, $data) as $line) |
|
|
|
|
{ |
|
|
|
|
$lines[] = trim( |
|
|
|
|
preg_replace( |
|
|
|
|
array_keys( |
|
|
|
|
$this->_dictionary |
|
|
|
|
), |
|
|
|
|
array_values( |
|
|
|
|
$this->_dictionary |
|
|
|
|
), |
|
|
|
|
trim( |
|
|
|
|
$line |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
$lines[] = preg_replace( |
|
|
|
|
array_keys( |
|
|
|
|
$this->_dictionary |
|
|
|
|
), |
|
|
|
|
array_values( |
|
|
|
|
$this->_dictionary |
|
|
|
|
), |
|
|
|
|
$line |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return implode( |
|
|
|
|
PHP_EOL, |
|
|
|
|
$lines |
|
|
|
|
return preg_replace( |
|
|
|
|
'/[\n\r]{2,}/', |
|
|
|
|
PHP_EOL . PHP_EOL, |
|
|
|
|
implode( |
|
|
|
|
PHP_EOL, |
|
|
|
|
$lines |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |