From ba326b9b3c81a4978362820b7ba8d9b45eee1dce Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 4 Feb 2024 01:08:11 +0200 Subject: [PATCH] fix empty lines quantity, init media links support --- src/Dokuwiki/Reader.php | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Dokuwiki/Reader.php b/src/Dokuwiki/Reader.php index e1bc221..a246163 100644 --- a/src/Dokuwiki/Reader.php +++ b/src/Dokuwiki/Reader.php @@ -16,19 +16,19 @@ class Reader private array $_rule = [ // Headers - '/^([\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, + '/^([\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, // Tags '/\*\*([^\*]{2,})\*\*/' => '$1', @@ -43,11 +43,11 @@ class Reader '/\[\[([^\[]+)\[([A-f:0-9]*)\]([^\]]+)\]\]/' => '$1~IPv6:open~$2~IPv6:close~$3', /// Remove extra spaces - '/\[\[\s?([^\|]+)\s?\|\s?([^\]]+)\s?\]\]/' => '[[$1|$2]]', - '/\[\[\s?([^\]]+)\s?\]\]/' => '[[$1]]', + '/\[\[\s*([^\|]+)\s*\|\s*([^\]]+)\s*\]\]/' => '[[$1|$2]]', + '/\[\[\s*([^\]]+)\s*\]\]/' => '[[$1]]', - '/\{\{\s?([^\|]+)\s?\|\s?([^\}]+)\s?\}\}/' => '{{$1|$2}}', - '/\{\{\s?([^\}]+)\s?\}\}/' => '{{$1}}', + '/\{\{\s*([^\|]+)\s*\|\s*([^\}]+)\s*\}\}/' => '{{$1|$2}}', + '/\{\{\s*([^\}]+)\s*\}\}/' => '{{$1}}', /// Wikipedia '/\[\[wp([A-z]{2,})>([^\|]+)\|([^\]]+)\]\]/ui' => '$3 ( https://$1.wikipedia.org/wiki/$2 )', @@ -75,6 +75,10 @@ class Reader '/\[\[(https?:)([^\|]+)\|([^\]]+)\]\]/i' => '$3 ( $1$2 )', '/\[\[(https?:)([^\]]+)\]\]/i' => '$1$2', // @TODO + /// Media + '/\{\{(?!https?:)([^\|]+)\|([^\}]+)\}\}/i' => PHP_EOL . '=> /$1$2' . PHP_EOL, + '/\{\{(?!https?:)([^\}]+)\}\}/i' => PHP_EOL . '=> /$1$2' . PHP_EOL, + // List '/^[\s]?-/' => '* ', '/^[\s]+\*/' => '*',