Browse Source

update dictionary

main
ghost 10 months ago
parent
commit
9ea658a3fc
  1. 80
      src/Dokuwiki.php

80
src/Dokuwiki.php

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