@@ -6,6 +6,6 @@ |
||
6 | 6 | $baseDir = dirname($vendorDir); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Pug\\' => array($vendorDir . '/pug-php/pug/src'), |
|
10 | - 'Jade\\' => array($vendorDir . '/pug-php/pug/src'), |
|
9 | + 'Pug\\' => array($vendorDir . '/pug-php/pug/src'), |
|
10 | + 'Jade\\' => array($vendorDir . '/pug-php/pug/src'), |
|
11 | 11 | ); |
@@ -6,28 +6,28 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitb1e7ddc74da87434be0b5632a8bb4210 |
8 | 8 | { |
9 | - public static $prefixesPsr0 = array ( |
|
10 | - 'P' => |
|
11 | - array ( |
|
12 | - 'Pug\\' => |
|
13 | - array ( |
|
14 | - 0 => __DIR__ . '/..' . '/pug-php/pug/src', |
|
15 | - ), |
|
16 | - ), |
|
17 | - 'J' => |
|
18 | - array ( |
|
19 | - 'Jade\\' => |
|
20 | - array ( |
|
21 | - 0 => __DIR__ . '/..' . '/pug-php/pug/src', |
|
22 | - ), |
|
23 | - ), |
|
24 | - ); |
|
9 | + public static $prefixesPsr0 = array ( |
|
10 | + 'P' => |
|
11 | + array ( |
|
12 | + 'Pug\\' => |
|
13 | + array ( |
|
14 | + 0 => __DIR__ . '/..' . '/pug-php/pug/src', |
|
15 | + ), |
|
16 | + ), |
|
17 | + 'J' => |
|
18 | + array ( |
|
19 | + 'Jade\\' => |
|
20 | + array ( |
|
21 | + 0 => __DIR__ . '/..' . '/pug-php/pug/src', |
|
22 | + ), |
|
23 | + ), |
|
24 | + ); |
|
25 | 25 | |
26 | - public static function getInitializer(ClassLoader $loader) |
|
27 | - { |
|
28 | - return \Closure::bind(function () use ($loader) { |
|
29 | - $loader->prefixesPsr0 = ComposerStaticInitb1e7ddc74da87434be0b5632a8bb4210::$prefixesPsr0; |
|
26 | + public static function getInitializer(ClassLoader $loader) |
|
27 | + { |
|
28 | + return \Closure::bind(function () use ($loader) { |
|
29 | + $loader->prefixesPsr0 = ComposerStaticInitb1e7ddc74da87434be0b5632a8bb4210::$prefixesPsr0; |
|
30 | 30 | |
31 | - }, null, ClassLoader::class); |
|
32 | - } |
|
31 | + }, null, ClassLoader::class); |
|
32 | + } |
|
33 | 33 | } |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class ComposerAutoloaderInitb1e7ddc74da87434be0b5632a8bb4210 |
6 | 6 | { |
7 | - private static $loader; |
|
8 | - |
|
9 | - public static function loadClassLoader($class) |
|
10 | - { |
|
11 | - if ('Composer\Autoload\ClassLoader' === $class) { |
|
12 | - require __DIR__ . '/ClassLoader.php'; |
|
13 | - } |
|
14 | - } |
|
15 | - |
|
16 | - public static function getLoader() |
|
17 | - { |
|
18 | - if (null !== self::$loader) { |
|
19 | - return self::$loader; |
|
20 | - } |
|
21 | - |
|
22 | - spl_autoload_register(array('ComposerAutoloaderInitb1e7ddc74da87434be0b5632a8bb4210', 'loadClassLoader'), true, true); |
|
23 | - self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
|
24 | - spl_autoload_unregister(array('ComposerAutoloaderInitb1e7ddc74da87434be0b5632a8bb4210', 'loadClassLoader')); |
|
25 | - |
|
26 | - $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); |
|
27 | - if ($useStaticLoader) { |
|
28 | - require_once __DIR__ . '/autoload_static.php'; |
|
29 | - |
|
30 | - call_user_func(\Composer\Autoload\ComposerStaticInitb1e7ddc74da87434be0b5632a8bb4210::getInitializer($loader)); |
|
31 | - } else { |
|
32 | - $map = require __DIR__ . '/autoload_namespaces.php'; |
|
33 | - foreach ($map as $namespace => $path) { |
|
34 | - $loader->set($namespace, $path); |
|
35 | - } |
|
36 | - |
|
37 | - $map = require __DIR__ . '/autoload_psr4.php'; |
|
38 | - foreach ($map as $namespace => $path) { |
|
39 | - $loader->setPsr4($namespace, $path); |
|
40 | - } |
|
41 | - |
|
42 | - $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
43 | - if ($classMap) { |
|
44 | - $loader->addClassMap($classMap); |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - $loader->register(true); |
|
49 | - |
|
50 | - return $loader; |
|
51 | - } |
|
7 | + private static $loader; |
|
8 | + |
|
9 | + public static function loadClassLoader($class) |
|
10 | + { |
|
11 | + if ('Composer\Autoload\ClassLoader' === $class) { |
|
12 | + require __DIR__ . '/ClassLoader.php'; |
|
13 | + } |
|
14 | + } |
|
15 | + |
|
16 | + public static function getLoader() |
|
17 | + { |
|
18 | + if (null !== self::$loader) { |
|
19 | + return self::$loader; |
|
20 | + } |
|
21 | + |
|
22 | + spl_autoload_register(array('ComposerAutoloaderInitb1e7ddc74da87434be0b5632a8bb4210', 'loadClassLoader'), true, true); |
|
23 | + self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
|
24 | + spl_autoload_unregister(array('ComposerAutoloaderInitb1e7ddc74da87434be0b5632a8bb4210', 'loadClassLoader')); |
|
25 | + |
|
26 | + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); |
|
27 | + if ($useStaticLoader) { |
|
28 | + require_once __DIR__ . '/autoload_static.php'; |
|
29 | + |
|
30 | + call_user_func(\Composer\Autoload\ComposerStaticInitb1e7ddc74da87434be0b5632a8bb4210::getInitializer($loader)); |
|
31 | + } else { |
|
32 | + $map = require __DIR__ . '/autoload_namespaces.php'; |
|
33 | + foreach ($map as $namespace => $path) { |
|
34 | + $loader->set($namespace, $path); |
|
35 | + } |
|
36 | + |
|
37 | + $map = require __DIR__ . '/autoload_psr4.php'; |
|
38 | + foreach ($map as $namespace => $path) { |
|
39 | + $loader->setPsr4($namespace, $path); |
|
40 | + } |
|
41 | + |
|
42 | + $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
43 | + if ($classMap) { |
|
44 | + $loader->addClassMap($classMap); |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + $loader->register(true); |
|
49 | + |
|
50 | + return $loader; |
|
51 | + } |
|
52 | 52 | } |
@@ -42,364 +42,364 @@ discard block |
||
42 | 42 | */ |
43 | 43 | class ClassLoader |
44 | 44 | { |
45 | - // PSR-4 |
|
46 | - private $prefixLengthsPsr4 = array(); |
|
47 | - private $prefixDirsPsr4 = array(); |
|
48 | - private $fallbackDirsPsr4 = array(); |
|
49 | - |
|
50 | - // PSR-0 |
|
51 | - private $prefixesPsr0 = array(); |
|
52 | - private $fallbackDirsPsr0 = array(); |
|
53 | - |
|
54 | - private $useIncludePath = false; |
|
55 | - private $classMap = array(); |
|
56 | - |
|
57 | - private $classMapAuthoritative = false; |
|
58 | - |
|
59 | - public function getPrefixes() |
|
60 | - { |
|
61 | - if (!empty($this->prefixesPsr0)) { |
|
62 | - return call_user_func_array('array_merge', $this->prefixesPsr0); |
|
63 | - } |
|
64 | - |
|
65 | - return array(); |
|
66 | - } |
|
67 | - |
|
68 | - public function getPrefixesPsr4() |
|
69 | - { |
|
70 | - return $this->prefixDirsPsr4; |
|
71 | - } |
|
72 | - |
|
73 | - public function getFallbackDirs() |
|
74 | - { |
|
75 | - return $this->fallbackDirsPsr0; |
|
76 | - } |
|
77 | - |
|
78 | - public function getFallbackDirsPsr4() |
|
79 | - { |
|
80 | - return $this->fallbackDirsPsr4; |
|
81 | - } |
|
82 | - |
|
83 | - public function getClassMap() |
|
84 | - { |
|
85 | - return $this->classMap; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param array $classMap Class to filename map |
|
90 | - */ |
|
91 | - public function addClassMap(array $classMap) |
|
92 | - { |
|
93 | - if ($this->classMap) { |
|
94 | - $this->classMap = array_merge($this->classMap, $classMap); |
|
95 | - } else { |
|
96 | - $this->classMap = $classMap; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Registers a set of PSR-0 directories for a given prefix, either |
|
102 | - * appending or prepending to the ones previously set for this prefix. |
|
103 | - * |
|
104 | - * @param string $prefix The prefix |
|
105 | - * @param array|string $paths The PSR-0 root directories |
|
106 | - * @param bool $prepend Whether to prepend the directories |
|
107 | - */ |
|
108 | - public function add($prefix, $paths, $prepend = false) |
|
109 | - { |
|
110 | - if (!$prefix) { |
|
111 | - if ($prepend) { |
|
112 | - $this->fallbackDirsPsr0 = array_merge( |
|
113 | - (array) $paths, |
|
114 | - $this->fallbackDirsPsr0 |
|
115 | - ); |
|
116 | - } else { |
|
117 | - $this->fallbackDirsPsr0 = array_merge( |
|
118 | - $this->fallbackDirsPsr0, |
|
119 | - (array) $paths |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - return; |
|
124 | - } |
|
125 | - |
|
126 | - $first = $prefix[0]; |
|
127 | - if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
128 | - $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
129 | - |
|
130 | - return; |
|
131 | - } |
|
132 | - if ($prepend) { |
|
133 | - $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
134 | - (array) $paths, |
|
135 | - $this->prefixesPsr0[$first][$prefix] |
|
136 | - ); |
|
137 | - } else { |
|
138 | - $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
139 | - $this->prefixesPsr0[$first][$prefix], |
|
140 | - (array) $paths |
|
141 | - ); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Registers a set of PSR-4 directories for a given namespace, either |
|
147 | - * appending or prepending to the ones previously set for this namespace. |
|
148 | - * |
|
149 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
150 | - * @param array|string $paths The PSR-4 base directories |
|
151 | - * @param bool $prepend Whether to prepend the directories |
|
152 | - * |
|
153 | - * @throws \InvalidArgumentException |
|
154 | - */ |
|
155 | - public function addPsr4($prefix, $paths, $prepend = false) |
|
156 | - { |
|
157 | - if (!$prefix) { |
|
158 | - // Register directories for the root namespace. |
|
159 | - if ($prepend) { |
|
160 | - $this->fallbackDirsPsr4 = array_merge( |
|
161 | - (array) $paths, |
|
162 | - $this->fallbackDirsPsr4 |
|
163 | - ); |
|
164 | - } else { |
|
165 | - $this->fallbackDirsPsr4 = array_merge( |
|
166 | - $this->fallbackDirsPsr4, |
|
167 | - (array) $paths |
|
168 | - ); |
|
169 | - } |
|
170 | - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
171 | - // Register directories for a new namespace. |
|
172 | - $length = strlen($prefix); |
|
173 | - if ('\\' !== $prefix[$length - 1]) { |
|
174 | - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
175 | - } |
|
176 | - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
177 | - $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
178 | - } elseif ($prepend) { |
|
179 | - // Prepend directories for an already registered namespace. |
|
180 | - $this->prefixDirsPsr4[$prefix] = array_merge( |
|
181 | - (array) $paths, |
|
182 | - $this->prefixDirsPsr4[$prefix] |
|
183 | - ); |
|
184 | - } else { |
|
185 | - // Append directories for an already registered namespace. |
|
186 | - $this->prefixDirsPsr4[$prefix] = array_merge( |
|
187 | - $this->prefixDirsPsr4[$prefix], |
|
188 | - (array) $paths |
|
189 | - ); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Registers a set of PSR-0 directories for a given prefix, |
|
195 | - * replacing any others previously set for this prefix. |
|
196 | - * |
|
197 | - * @param string $prefix The prefix |
|
198 | - * @param array|string $paths The PSR-0 base directories |
|
199 | - */ |
|
200 | - public function set($prefix, $paths) |
|
201 | - { |
|
202 | - if (!$prefix) { |
|
203 | - $this->fallbackDirsPsr0 = (array) $paths; |
|
204 | - } else { |
|
205 | - $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Registers a set of PSR-4 directories for a given namespace, |
|
211 | - * replacing any others previously set for this namespace. |
|
212 | - * |
|
213 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
214 | - * @param array|string $paths The PSR-4 base directories |
|
215 | - * |
|
216 | - * @throws \InvalidArgumentException |
|
217 | - */ |
|
218 | - public function setPsr4($prefix, $paths) |
|
219 | - { |
|
220 | - if (!$prefix) { |
|
221 | - $this->fallbackDirsPsr4 = (array) $paths; |
|
222 | - } else { |
|
223 | - $length = strlen($prefix); |
|
224 | - if ('\\' !== $prefix[$length - 1]) { |
|
225 | - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
226 | - } |
|
227 | - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
228 | - $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Turns on searching the include path for class files. |
|
234 | - * |
|
235 | - * @param bool $useIncludePath |
|
236 | - */ |
|
237 | - public function setUseIncludePath($useIncludePath) |
|
238 | - { |
|
239 | - $this->useIncludePath = $useIncludePath; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Can be used to check if the autoloader uses the include path to check |
|
244 | - * for classes. |
|
245 | - * |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function getUseIncludePath() |
|
249 | - { |
|
250 | - return $this->useIncludePath; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Turns off searching the prefix and fallback directories for classes |
|
255 | - * that have not been registered with the class map. |
|
256 | - * |
|
257 | - * @param bool $classMapAuthoritative |
|
258 | - */ |
|
259 | - public function setClassMapAuthoritative($classMapAuthoritative) |
|
260 | - { |
|
261 | - $this->classMapAuthoritative = $classMapAuthoritative; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Should class lookup fail if not found in the current class map? |
|
266 | - * |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function isClassMapAuthoritative() |
|
270 | - { |
|
271 | - return $this->classMapAuthoritative; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Registers this instance as an autoloader. |
|
276 | - * |
|
277 | - * @param bool $prepend Whether to prepend the autoloader or not |
|
278 | - */ |
|
279 | - public function register($prepend = false) |
|
280 | - { |
|
281 | - spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Unregisters this instance as an autoloader. |
|
286 | - */ |
|
287 | - public function unregister() |
|
288 | - { |
|
289 | - spl_autoload_unregister(array($this, 'loadClass')); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Loads the given class or interface. |
|
294 | - * |
|
295 | - * @param string $class The name of the class |
|
296 | - * @return bool|null True if loaded, null otherwise |
|
297 | - */ |
|
298 | - public function loadClass($class) |
|
299 | - { |
|
300 | - if ($file = $this->findFile($class)) { |
|
301 | - includeFile($file); |
|
302 | - |
|
303 | - return true; |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Finds the path to the file where the class is defined. |
|
309 | - * |
|
310 | - * @param string $class The name of the class |
|
311 | - * |
|
312 | - * @return string|false The path if found, false otherwise |
|
313 | - */ |
|
314 | - public function findFile($class) |
|
315 | - { |
|
316 | - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 |
|
317 | - if ('\\' == $class[0]) { |
|
318 | - $class = substr($class, 1); |
|
319 | - } |
|
320 | - |
|
321 | - // class map lookup |
|
322 | - if (isset($this->classMap[$class])) { |
|
323 | - return $this->classMap[$class]; |
|
324 | - } |
|
325 | - if ($this->classMapAuthoritative) { |
|
326 | - return false; |
|
327 | - } |
|
328 | - |
|
329 | - $file = $this->findFileWithExtension($class, '.php'); |
|
330 | - |
|
331 | - // Search for Hack files if we are running on HHVM |
|
332 | - if ($file === null && defined('HHVM_VERSION')) { |
|
333 | - $file = $this->findFileWithExtension($class, '.hh'); |
|
334 | - } |
|
335 | - |
|
336 | - if ($file === null) { |
|
337 | - // Remember that this class does not exist. |
|
338 | - return $this->classMap[$class] = false; |
|
339 | - } |
|
340 | - |
|
341 | - return $file; |
|
342 | - } |
|
343 | - |
|
344 | - private function findFileWithExtension($class, $ext) |
|
345 | - { |
|
346 | - // PSR-4 lookup |
|
347 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
348 | - |
|
349 | - $first = $class[0]; |
|
350 | - if (isset($this->prefixLengthsPsr4[$first])) { |
|
351 | - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { |
|
352 | - if (0 === strpos($class, $prefix)) { |
|
353 | - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { |
|
354 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { |
|
355 | - return $file; |
|
356 | - } |
|
357 | - } |
|
358 | - } |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - // PSR-4 fallback dirs |
|
363 | - foreach ($this->fallbackDirsPsr4 as $dir) { |
|
364 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
365 | - return $file; |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - // PSR-0 lookup |
|
370 | - if (false !== $pos = strrpos($class, '\\')) { |
|
371 | - // namespaced class name |
|
372 | - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
373 | - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
374 | - } else { |
|
375 | - // PEAR-like class name |
|
376 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
377 | - } |
|
378 | - |
|
379 | - if (isset($this->prefixesPsr0[$first])) { |
|
380 | - foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
381 | - if (0 === strpos($class, $prefix)) { |
|
382 | - foreach ($dirs as $dir) { |
|
383 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
384 | - return $file; |
|
385 | - } |
|
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - // PSR-0 fallback dirs |
|
392 | - foreach ($this->fallbackDirsPsr0 as $dir) { |
|
393 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
394 | - return $file; |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - // PSR-0 include paths. |
|
399 | - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
400 | - return $file; |
|
401 | - } |
|
402 | - } |
|
45 | + // PSR-4 |
|
46 | + private $prefixLengthsPsr4 = array(); |
|
47 | + private $prefixDirsPsr4 = array(); |
|
48 | + private $fallbackDirsPsr4 = array(); |
|
49 | + |
|
50 | + // PSR-0 |
|
51 | + private $prefixesPsr0 = array(); |
|
52 | + private $fallbackDirsPsr0 = array(); |
|
53 | + |
|
54 | + private $useIncludePath = false; |
|
55 | + private $classMap = array(); |
|
56 | + |
|
57 | + private $classMapAuthoritative = false; |
|
58 | + |
|
59 | + public function getPrefixes() |
|
60 | + { |
|
61 | + if (!empty($this->prefixesPsr0)) { |
|
62 | + return call_user_func_array('array_merge', $this->prefixesPsr0); |
|
63 | + } |
|
64 | + |
|
65 | + return array(); |
|
66 | + } |
|
67 | + |
|
68 | + public function getPrefixesPsr4() |
|
69 | + { |
|
70 | + return $this->prefixDirsPsr4; |
|
71 | + } |
|
72 | + |
|
73 | + public function getFallbackDirs() |
|
74 | + { |
|
75 | + return $this->fallbackDirsPsr0; |
|
76 | + } |
|
77 | + |
|
78 | + public function getFallbackDirsPsr4() |
|
79 | + { |
|
80 | + return $this->fallbackDirsPsr4; |
|
81 | + } |
|
82 | + |
|
83 | + public function getClassMap() |
|
84 | + { |
|
85 | + return $this->classMap; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param array $classMap Class to filename map |
|
90 | + */ |
|
91 | + public function addClassMap(array $classMap) |
|
92 | + { |
|
93 | + if ($this->classMap) { |
|
94 | + $this->classMap = array_merge($this->classMap, $classMap); |
|
95 | + } else { |
|
96 | + $this->classMap = $classMap; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Registers a set of PSR-0 directories for a given prefix, either |
|
102 | + * appending or prepending to the ones previously set for this prefix. |
|
103 | + * |
|
104 | + * @param string $prefix The prefix |
|
105 | + * @param array|string $paths The PSR-0 root directories |
|
106 | + * @param bool $prepend Whether to prepend the directories |
|
107 | + */ |
|
108 | + public function add($prefix, $paths, $prepend = false) |
|
109 | + { |
|
110 | + if (!$prefix) { |
|
111 | + if ($prepend) { |
|
112 | + $this->fallbackDirsPsr0 = array_merge( |
|
113 | + (array) $paths, |
|
114 | + $this->fallbackDirsPsr0 |
|
115 | + ); |
|
116 | + } else { |
|
117 | + $this->fallbackDirsPsr0 = array_merge( |
|
118 | + $this->fallbackDirsPsr0, |
|
119 | + (array) $paths |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + return; |
|
124 | + } |
|
125 | + |
|
126 | + $first = $prefix[0]; |
|
127 | + if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
128 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
129 | + |
|
130 | + return; |
|
131 | + } |
|
132 | + if ($prepend) { |
|
133 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
134 | + (array) $paths, |
|
135 | + $this->prefixesPsr0[$first][$prefix] |
|
136 | + ); |
|
137 | + } else { |
|
138 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
139 | + $this->prefixesPsr0[$first][$prefix], |
|
140 | + (array) $paths |
|
141 | + ); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Registers a set of PSR-4 directories for a given namespace, either |
|
147 | + * appending or prepending to the ones previously set for this namespace. |
|
148 | + * |
|
149 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
150 | + * @param array|string $paths The PSR-4 base directories |
|
151 | + * @param bool $prepend Whether to prepend the directories |
|
152 | + * |
|
153 | + * @throws \InvalidArgumentException |
|
154 | + */ |
|
155 | + public function addPsr4($prefix, $paths, $prepend = false) |
|
156 | + { |
|
157 | + if (!$prefix) { |
|
158 | + // Register directories for the root namespace. |
|
159 | + if ($prepend) { |
|
160 | + $this->fallbackDirsPsr4 = array_merge( |
|
161 | + (array) $paths, |
|
162 | + $this->fallbackDirsPsr4 |
|
163 | + ); |
|
164 | + } else { |
|
165 | + $this->fallbackDirsPsr4 = array_merge( |
|
166 | + $this->fallbackDirsPsr4, |
|
167 | + (array) $paths |
|
168 | + ); |
|
169 | + } |
|
170 | + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
171 | + // Register directories for a new namespace. |
|
172 | + $length = strlen($prefix); |
|
173 | + if ('\\' !== $prefix[$length - 1]) { |
|
174 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
175 | + } |
|
176 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
177 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
178 | + } elseif ($prepend) { |
|
179 | + // Prepend directories for an already registered namespace. |
|
180 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
181 | + (array) $paths, |
|
182 | + $this->prefixDirsPsr4[$prefix] |
|
183 | + ); |
|
184 | + } else { |
|
185 | + // Append directories for an already registered namespace. |
|
186 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
187 | + $this->prefixDirsPsr4[$prefix], |
|
188 | + (array) $paths |
|
189 | + ); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Registers a set of PSR-0 directories for a given prefix, |
|
195 | + * replacing any others previously set for this prefix. |
|
196 | + * |
|
197 | + * @param string $prefix The prefix |
|
198 | + * @param array|string $paths The PSR-0 base directories |
|
199 | + */ |
|
200 | + public function set($prefix, $paths) |
|
201 | + { |
|
202 | + if (!$prefix) { |
|
203 | + $this->fallbackDirsPsr0 = (array) $paths; |
|
204 | + } else { |
|
205 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Registers a set of PSR-4 directories for a given namespace, |
|
211 | + * replacing any others previously set for this namespace. |
|
212 | + * |
|
213 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
214 | + * @param array|string $paths The PSR-4 base directories |
|
215 | + * |
|
216 | + * @throws \InvalidArgumentException |
|
217 | + */ |
|
218 | + public function setPsr4($prefix, $paths) |
|
219 | + { |
|
220 | + if (!$prefix) { |
|
221 | + $this->fallbackDirsPsr4 = (array) $paths; |
|
222 | + } else { |
|
223 | + $length = strlen($prefix); |
|
224 | + if ('\\' !== $prefix[$length - 1]) { |
|
225 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
226 | + } |
|
227 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
228 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Turns on searching the include path for class files. |
|
234 | + * |
|
235 | + * @param bool $useIncludePath |
|
236 | + */ |
|
237 | + public function setUseIncludePath($useIncludePath) |
|
238 | + { |
|
239 | + $this->useIncludePath = $useIncludePath; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Can be used to check if the autoloader uses the include path to check |
|
244 | + * for classes. |
|
245 | + * |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function getUseIncludePath() |
|
249 | + { |
|
250 | + return $this->useIncludePath; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Turns off searching the prefix and fallback directories for classes |
|
255 | + * that have not been registered with the class map. |
|
256 | + * |
|
257 | + * @param bool $classMapAuthoritative |
|
258 | + */ |
|
259 | + public function setClassMapAuthoritative($classMapAuthoritative) |
|
260 | + { |
|
261 | + $this->classMapAuthoritative = $classMapAuthoritative; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Should class lookup fail if not found in the current class map? |
|
266 | + * |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function isClassMapAuthoritative() |
|
270 | + { |
|
271 | + return $this->classMapAuthoritative; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Registers this instance as an autoloader. |
|
276 | + * |
|
277 | + * @param bool $prepend Whether to prepend the autoloader or not |
|
278 | + */ |
|
279 | + public function register($prepend = false) |
|
280 | + { |
|
281 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Unregisters this instance as an autoloader. |
|
286 | + */ |
|
287 | + public function unregister() |
|
288 | + { |
|
289 | + spl_autoload_unregister(array($this, 'loadClass')); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Loads the given class or interface. |
|
294 | + * |
|
295 | + * @param string $class The name of the class |
|
296 | + * @return bool|null True if loaded, null otherwise |
|
297 | + */ |
|
298 | + public function loadClass($class) |
|
299 | + { |
|
300 | + if ($file = $this->findFile($class)) { |
|
301 | + includeFile($file); |
|
302 | + |
|
303 | + return true; |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Finds the path to the file where the class is defined. |
|
309 | + * |
|
310 | + * @param string $class The name of the class |
|
311 | + * |
|
312 | + * @return string|false The path if found, false otherwise |
|
313 | + */ |
|
314 | + public function findFile($class) |
|
315 | + { |
|
316 | + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 |
|
317 | + if ('\\' == $class[0]) { |
|
318 | + $class = substr($class, 1); |
|
319 | + } |
|
320 | + |
|
321 | + // class map lookup |
|
322 | + if (isset($this->classMap[$class])) { |
|
323 | + return $this->classMap[$class]; |
|
324 | + } |
|
325 | + if ($this->classMapAuthoritative) { |
|
326 | + return false; |
|
327 | + } |
|
328 | + |
|
329 | + $file = $this->findFileWithExtension($class, '.php'); |
|
330 | + |
|
331 | + // Search for Hack files if we are running on HHVM |
|
332 | + if ($file === null && defined('HHVM_VERSION')) { |
|
333 | + $file = $this->findFileWithExtension($class, '.hh'); |
|
334 | + } |
|
335 | + |
|
336 | + if ($file === null) { |
|
337 | + // Remember that this class does not exist. |
|
338 | + return $this->classMap[$class] = false; |
|
339 | + } |
|
340 | + |
|
341 | + return $file; |
|
342 | + } |
|
343 | + |
|
344 | + private function findFileWithExtension($class, $ext) |
|
345 | + { |
|
346 | + // PSR-4 lookup |
|
347 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
348 | + |
|
349 | + $first = $class[0]; |
|
350 | + if (isset($this->prefixLengthsPsr4[$first])) { |
|
351 | + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { |
|
352 | + if (0 === strpos($class, $prefix)) { |
|
353 | + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { |
|
354 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { |
|
355 | + return $file; |
|
356 | + } |
|
357 | + } |
|
358 | + } |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + // PSR-4 fallback dirs |
|
363 | + foreach ($this->fallbackDirsPsr4 as $dir) { |
|
364 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
365 | + return $file; |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + // PSR-0 lookup |
|
370 | + if (false !== $pos = strrpos($class, '\\')) { |
|
371 | + // namespaced class name |
|
372 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
373 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
374 | + } else { |
|
375 | + // PEAR-like class name |
|
376 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
377 | + } |
|
378 | + |
|
379 | + if (isset($this->prefixesPsr0[$first])) { |
|
380 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
381 | + if (0 === strpos($class, $prefix)) { |
|
382 | + foreach ($dirs as $dir) { |
|
383 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
384 | + return $file; |
|
385 | + } |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + // PSR-0 fallback dirs |
|
392 | + foreach ($this->fallbackDirsPsr0 as $dir) { |
|
393 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
394 | + return $file; |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + // PSR-0 include paths. |
|
399 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
400 | + return $file; |
|
401 | + } |
|
402 | + } |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -409,5 +409,5 @@ discard block |
||
409 | 409 | */ |
410 | 410 | function includeFile($file) |
411 | 411 | { |
412 | - include $file; |
|
412 | + include $file; |
|
413 | 413 | } |
@@ -15,1524 +15,1524 @@ |
||
15 | 15 | |
16 | 16 | class Parsedown |
17 | 17 | { |
18 | - # ~ |
|
18 | + # ~ |
|
19 | 19 | |
20 | - const version = '1.6.0'; |
|
20 | + const version = '1.6.0'; |
|
21 | 21 | |
22 | - # ~ |
|
22 | + # ~ |
|
23 | 23 | |
24 | - function text($text) |
|
25 | - { |
|
26 | - # make sure no definitions are set |
|
27 | - $this->DefinitionData = array(); |
|
28 | - |
|
29 | - # standardize line breaks |
|
30 | - $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
31 | - |
|
32 | - # remove surrounding line breaks |
|
33 | - $text = trim($text, "\n"); |
|
34 | - |
|
35 | - # split text into lines |
|
36 | - $lines = explode("\n", $text); |
|
37 | - |
|
38 | - # iterate through lines to identify blocks |
|
39 | - $markup = $this->lines($lines); |
|
24 | + function text($text) |
|
25 | + { |
|
26 | + # make sure no definitions are set |
|
27 | + $this->DefinitionData = array(); |
|
28 | + |
|
29 | + # standardize line breaks |
|
30 | + $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
31 | + |
|
32 | + # remove surrounding line breaks |
|
33 | + $text = trim($text, "\n"); |
|
34 | + |
|
35 | + # split text into lines |
|
36 | + $lines = explode("\n", $text); |
|
37 | + |
|
38 | + # iterate through lines to identify blocks |
|
39 | + $markup = $this->lines($lines); |
|
40 | 40 | |
41 | - # trim line breaks |
|
42 | - $markup = trim($markup, "\n"); |
|
41 | + # trim line breaks |
|
42 | + $markup = trim($markup, "\n"); |
|
43 | 43 | |
44 | - return $markup; |
|
45 | - } |
|
44 | + return $markup; |
|
45 | + } |
|
46 | 46 | |
47 | - # |
|
48 | - # Setters |
|
49 | - # |
|
47 | + # |
|
48 | + # Setters |
|
49 | + # |
|
50 | 50 | |
51 | - function setBreaksEnabled($breaksEnabled) |
|
52 | - { |
|
53 | - $this->breaksEnabled = $breaksEnabled; |
|
51 | + function setBreaksEnabled($breaksEnabled) |
|
52 | + { |
|
53 | + $this->breaksEnabled = $breaksEnabled; |
|
54 | 54 | |
55 | - return $this; |
|
56 | - } |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - protected $breaksEnabled; |
|
58 | + protected $breaksEnabled; |
|
59 | 59 | |
60 | - function setMarkupEscaped($markupEscaped) |
|
61 | - { |
|
62 | - $this->markupEscaped = $markupEscaped; |
|
60 | + function setMarkupEscaped($markupEscaped) |
|
61 | + { |
|
62 | + $this->markupEscaped = $markupEscaped; |
|
63 | 63 | |
64 | - return $this; |
|
65 | - } |
|
64 | + return $this; |
|
65 | + } |
|
66 | 66 | |
67 | - protected $markupEscaped; |
|
67 | + protected $markupEscaped; |
|
68 | 68 | |
69 | - function setUrlsLinked($urlsLinked) |
|
70 | - { |
|
71 | - $this->urlsLinked = $urlsLinked; |
|
69 | + function setUrlsLinked($urlsLinked) |
|
70 | + { |
|
71 | + $this->urlsLinked = $urlsLinked; |
|
72 | 72 | |
73 | - return $this; |
|
74 | - } |
|
73 | + return $this; |
|
74 | + } |
|
75 | 75 | |
76 | - protected $urlsLinked = true; |
|
76 | + protected $urlsLinked = true; |
|
77 | 77 | |
78 | - # |
|
79 | - # Lines |
|
80 | - # |
|
78 | + # |
|
79 | + # Lines |
|
80 | + # |
|
81 | 81 | |
82 | - protected $BlockTypes = array( |
|
83 | - '#' => array('Header'), |
|
84 | - '*' => array('Rule', 'List'), |
|
85 | - '+' => array('List'), |
|
86 | - '-' => array('SetextHeader', 'Table', 'Rule', 'List'), |
|
87 | - '0' => array('List'), |
|
88 | - '1' => array('List'), |
|
89 | - '2' => array('List'), |
|
90 | - '3' => array('List'), |
|
91 | - '4' => array('List'), |
|
92 | - '5' => array('List'), |
|
93 | - '6' => array('List'), |
|
94 | - '7' => array('List'), |
|
95 | - '8' => array('List'), |
|
96 | - '9' => array('List'), |
|
97 | - ':' => array('Table'), |
|
98 | - '<' => array('Comment', 'Markup'), |
|
99 | - '=' => array('SetextHeader'), |
|
100 | - '>' => array('Quote'), |
|
101 | - '[' => array('Reference'), |
|
102 | - '_' => array('Rule'), |
|
103 | - '`' => array('FencedCode'), |
|
104 | - '|' => array('Table'), |
|
105 | - '~' => array('FencedCode'), |
|
106 | - ); |
|
82 | + protected $BlockTypes = array( |
|
83 | + '#' => array('Header'), |
|
84 | + '*' => array('Rule', 'List'), |
|
85 | + '+' => array('List'), |
|
86 | + '-' => array('SetextHeader', 'Table', 'Rule', 'List'), |
|
87 | + '0' => array('List'), |
|
88 | + '1' => array('List'), |
|
89 | + '2' => array('List'), |
|
90 | + '3' => array('List'), |
|
91 | + '4' => array('List'), |
|
92 | + '5' => array('List'), |
|
93 | + '6' => array('List'), |
|
94 | + '7' => array('List'), |
|
95 | + '8' => array('List'), |
|
96 | + '9' => array('List'), |
|
97 | + ':' => array('Table'), |
|
98 | + '<' => array('Comment', 'Markup'), |
|
99 | + '=' => array('SetextHeader'), |
|
100 | + '>' => array('Quote'), |
|
101 | + '[' => array('Reference'), |
|
102 | + '_' => array('Rule'), |
|
103 | + '`' => array('FencedCode'), |
|
104 | + '|' => array('Table'), |
|
105 | + '~' => array('FencedCode'), |
|
106 | + ); |
|
107 | 107 | |
108 | - # ~ |
|
108 | + # ~ |
|
109 | 109 | |
110 | - protected $unmarkedBlockTypes = array( |
|
111 | - 'Code', |
|
112 | - ); |
|
110 | + protected $unmarkedBlockTypes = array( |
|
111 | + 'Code', |
|
112 | + ); |
|
113 | 113 | |
114 | - # |
|
115 | - # Blocks |
|
116 | - # |
|
114 | + # |
|
115 | + # Blocks |
|
116 | + # |
|
117 | 117 | |
118 | - protected function lines(array $lines) |
|
119 | - { |
|
120 | - $CurrentBlock = null; |
|
118 | + protected function lines(array $lines) |
|
119 | + { |
|
120 | + $CurrentBlock = null; |
|
121 | 121 | |
122 | - foreach ($lines as $line) |
|
123 | - { |
|
124 | - if (chop($line) === '') |
|
125 | - { |
|
126 | - if (isset($CurrentBlock)) |
|
127 | - { |
|
128 | - $CurrentBlock['interrupted'] = true; |
|
129 | - } |
|
122 | + foreach ($lines as $line) |
|
123 | + { |
|
124 | + if (chop($line) === '') |
|
125 | + { |
|
126 | + if (isset($CurrentBlock)) |
|
127 | + { |
|
128 | + $CurrentBlock['interrupted'] = true; |
|
129 | + } |
|
130 | 130 | |
131 | - continue; |
|
132 | - } |
|
131 | + continue; |
|
132 | + } |
|
133 | 133 | |
134 | - if (strpos($line, "\t") !== false) |
|
135 | - { |
|
136 | - $parts = explode("\t", $line); |
|
134 | + if (strpos($line, "\t") !== false) |
|
135 | + { |
|
136 | + $parts = explode("\t", $line); |
|
137 | 137 | |
138 | - $line = $parts[0]; |
|
138 | + $line = $parts[0]; |
|
139 | 139 | |
140 | - unset($parts[0]); |
|
140 | + unset($parts[0]); |
|
141 | 141 | |
142 | - foreach ($parts as $part) |
|
143 | - { |
|
144 | - $shortage = 4 - mb_strlen($line, 'utf-8') % 4; |
|
142 | + foreach ($parts as $part) |
|
143 | + { |
|
144 | + $shortage = 4 - mb_strlen($line, 'utf-8') % 4; |
|
145 | 145 | |
146 | - $line .= str_repeat(' ', $shortage); |
|
147 | - $line .= $part; |
|
148 | - } |
|
149 | - } |
|
146 | + $line .= str_repeat(' ', $shortage); |
|
147 | + $line .= $part; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - $indent = 0; |
|
151 | + $indent = 0; |
|
152 | 152 | |
153 | - while (isset($line[$indent]) and $line[$indent] === ' ') |
|
154 | - { |
|
155 | - $indent ++; |
|
156 | - } |
|
153 | + while (isset($line[$indent]) and $line[$indent] === ' ') |
|
154 | + { |
|
155 | + $indent ++; |
|
156 | + } |
|
157 | 157 | |
158 | - $text = $indent > 0 ? substr($line, $indent) : $line; |
|
158 | + $text = $indent > 0 ? substr($line, $indent) : $line; |
|
159 | 159 | |
160 | - # ~ |
|
160 | + # ~ |
|
161 | 161 | |
162 | - $Line = array('body' => $line, 'indent' => $indent, 'text' => $text); |
|
162 | + $Line = array('body' => $line, 'indent' => $indent, 'text' => $text); |
|
163 | 163 | |
164 | - # ~ |
|
164 | + # ~ |
|
165 | 165 | |
166 | - if (isset($CurrentBlock['continuable'])) |
|
167 | - { |
|
168 | - $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock); |
|
166 | + if (isset($CurrentBlock['continuable'])) |
|
167 | + { |
|
168 | + $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock); |
|
169 | 169 | |
170 | - if (isset($Block)) |
|
171 | - { |
|
172 | - $CurrentBlock = $Block; |
|
170 | + if (isset($Block)) |
|
171 | + { |
|
172 | + $CurrentBlock = $Block; |
|
173 | 173 | |
174 | - continue; |
|
175 | - } |
|
176 | - else |
|
177 | - { |
|
178 | - if ($this->isBlockCompletable($CurrentBlock['type'])) |
|
179 | - { |
|
180 | - $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
174 | + continue; |
|
175 | + } |
|
176 | + else |
|
177 | + { |
|
178 | + if ($this->isBlockCompletable($CurrentBlock['type'])) |
|
179 | + { |
|
180 | + $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - # ~ |
|
185 | + # ~ |
|
186 | 186 | |
187 | - $marker = $text[0]; |
|
187 | + $marker = $text[0]; |
|
188 | 188 | |
189 | - # ~ |
|
189 | + # ~ |
|
190 | 190 | |
191 | - $blockTypes = $this->unmarkedBlockTypes; |
|
191 | + $blockTypes = $this->unmarkedBlockTypes; |
|
192 | 192 | |
193 | - if (isset($this->BlockTypes[$marker])) |
|
194 | - { |
|
195 | - foreach ($this->BlockTypes[$marker] as $blockType) |
|
196 | - { |
|
197 | - $blockTypes []= $blockType; |
|
198 | - } |
|
199 | - } |
|
193 | + if (isset($this->BlockTypes[$marker])) |
|
194 | + { |
|
195 | + foreach ($this->BlockTypes[$marker] as $blockType) |
|
196 | + { |
|
197 | + $blockTypes []= $blockType; |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | - # |
|
202 | - # ~ |
|
201 | + # |
|
202 | + # ~ |
|
203 | 203 | |
204 | - foreach ($blockTypes as $blockType) |
|
205 | - { |
|
206 | - $Block = $this->{'block'.$blockType}($Line, $CurrentBlock); |
|
204 | + foreach ($blockTypes as $blockType) |
|
205 | + { |
|
206 | + $Block = $this->{'block'.$blockType}($Line, $CurrentBlock); |
|
207 | 207 | |
208 | - if (isset($Block)) |
|
209 | - { |
|
210 | - $Block['type'] = $blockType; |
|
208 | + if (isset($Block)) |
|
209 | + { |
|
210 | + $Block['type'] = $blockType; |
|
211 | 211 | |
212 | - if ( ! isset($Block['identified'])) |
|
213 | - { |
|
214 | - $Blocks []= $CurrentBlock; |
|
212 | + if ( ! isset($Block['identified'])) |
|
213 | + { |
|
214 | + $Blocks []= $CurrentBlock; |
|
215 | 215 | |
216 | - $Block['identified'] = true; |
|
217 | - } |
|
216 | + $Block['identified'] = true; |
|
217 | + } |
|
218 | 218 | |
219 | - if ($this->isBlockContinuable($blockType)) |
|
220 | - { |
|
221 | - $Block['continuable'] = true; |
|
222 | - } |
|
219 | + if ($this->isBlockContinuable($blockType)) |
|
220 | + { |
|
221 | + $Block['continuable'] = true; |
|
222 | + } |
|
223 | 223 | |
224 | - $CurrentBlock = $Block; |
|
224 | + $CurrentBlock = $Block; |
|
225 | 225 | |
226 | - continue 2; |
|
227 | - } |
|
228 | - } |
|
226 | + continue 2; |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - # ~ |
|
230 | + # ~ |
|
231 | 231 | |
232 | - if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
|
233 | - { |
|
234 | - $CurrentBlock['element']['text'] .= "\n".$text; |
|
235 | - } |
|
236 | - else |
|
237 | - { |
|
238 | - $Blocks []= $CurrentBlock; |
|
232 | + if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
|
233 | + { |
|
234 | + $CurrentBlock['element']['text'] .= "\n".$text; |
|
235 | + } |
|
236 | + else |
|
237 | + { |
|
238 | + $Blocks []= $CurrentBlock; |
|
239 | 239 | |
240 | - $CurrentBlock = $this->paragraph($Line); |
|
240 | + $CurrentBlock = $this->paragraph($Line); |
|
241 | 241 | |
242 | - $CurrentBlock['identified'] = true; |
|
243 | - } |
|
244 | - } |
|
242 | + $CurrentBlock['identified'] = true; |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - # ~ |
|
246 | + # ~ |
|
247 | 247 | |
248 | - if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) |
|
249 | - { |
|
250 | - $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); |
|
251 | - } |
|
248 | + if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) |
|
249 | + { |
|
250 | + $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); |
|
251 | + } |
|
252 | 252 | |
253 | - # ~ |
|
253 | + # ~ |
|
254 | 254 | |
255 | - $Blocks []= $CurrentBlock; |
|
255 | + $Blocks []= $CurrentBlock; |
|
256 | 256 | |
257 | - unset($Blocks[0]); |
|
257 | + unset($Blocks[0]); |
|
258 | 258 | |
259 | - # ~ |
|
259 | + # ~ |
|
260 | 260 | |
261 | - $markup = ''; |
|
261 | + $markup = ''; |
|
262 | 262 | |
263 | - foreach ($Blocks as $Block) |
|
264 | - { |
|
265 | - if (isset($Block['hidden'])) |
|
266 | - { |
|
267 | - continue; |
|
268 | - } |
|
263 | + foreach ($Blocks as $Block) |
|
264 | + { |
|
265 | + if (isset($Block['hidden'])) |
|
266 | + { |
|
267 | + continue; |
|
268 | + } |
|
269 | 269 | |
270 | - $markup .= "\n"; |
|
271 | - $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']); |
|
272 | - } |
|
270 | + $markup .= "\n"; |
|
271 | + $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']); |
|
272 | + } |
|
273 | 273 | |
274 | - $markup .= "\n"; |
|
274 | + $markup .= "\n"; |
|
275 | 275 | |
276 | - # ~ |
|
276 | + # ~ |
|
277 | 277 | |
278 | - return $markup; |
|
279 | - } |
|
278 | + return $markup; |
|
279 | + } |
|
280 | 280 | |
281 | - protected function isBlockContinuable($Type) |
|
282 | - { |
|
283 | - return method_exists($this, 'block'.$Type.'Continue'); |
|
284 | - } |
|
281 | + protected function isBlockContinuable($Type) |
|
282 | + { |
|
283 | + return method_exists($this, 'block'.$Type.'Continue'); |
|
284 | + } |
|
285 | 285 | |
286 | - protected function isBlockCompletable($Type) |
|
287 | - { |
|
288 | - return method_exists($this, 'block'.$Type.'Complete'); |
|
289 | - } |
|
286 | + protected function isBlockCompletable($Type) |
|
287 | + { |
|
288 | + return method_exists($this, 'block'.$Type.'Complete'); |
|
289 | + } |
|
290 | 290 | |
291 | - # |
|
292 | - # Code |
|
291 | + # |
|
292 | + # Code |
|
293 | 293 | |
294 | - protected function blockCode($Line, $Block = null) |
|
295 | - { |
|
296 | - if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) |
|
297 | - { |
|
298 | - return; |
|
299 | - } |
|
294 | + protected function blockCode($Line, $Block = null) |
|
295 | + { |
|
296 | + if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) |
|
297 | + { |
|
298 | + return; |
|
299 | + } |
|
300 | 300 | |
301 | - if ($Line['indent'] >= 4) |
|
302 | - { |
|
303 | - $text = substr($Line['body'], 4); |
|
301 | + if ($Line['indent'] >= 4) |
|
302 | + { |
|
303 | + $text = substr($Line['body'], 4); |
|
304 | 304 | |
305 | - $Block = array( |
|
306 | - 'element' => array( |
|
307 | - 'name' => 'pre', |
|
308 | - 'handler' => 'element', |
|
309 | - 'text' => array( |
|
310 | - 'name' => 'code', |
|
311 | - 'text' => $text, |
|
312 | - ), |
|
313 | - ), |
|
314 | - ); |
|
305 | + $Block = array( |
|
306 | + 'element' => array( |
|
307 | + 'name' => 'pre', |
|
308 | + 'handler' => 'element', |
|
309 | + 'text' => array( |
|
310 | + 'name' => 'code', |
|
311 | + 'text' => $text, |
|
312 | + ), |
|
313 | + ), |
|
314 | + ); |
|
315 | 315 | |
316 | - return $Block; |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - protected function blockCodeContinue($Line, $Block) |
|
321 | - { |
|
322 | - if ($Line['indent'] >= 4) |
|
323 | - { |
|
324 | - if (isset($Block['interrupted'])) |
|
325 | - { |
|
326 | - $Block['element']['text']['text'] .= "\n"; |
|
327 | - |
|
328 | - unset($Block['interrupted']); |
|
329 | - } |
|
330 | - |
|
331 | - $Block['element']['text']['text'] .= "\n"; |
|
332 | - |
|
333 | - $text = substr($Line['body'], 4); |
|
334 | - |
|
335 | - $Block['element']['text']['text'] .= $text; |
|
336 | - |
|
337 | - return $Block; |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - protected function blockCodeComplete($Block) |
|
342 | - { |
|
343 | - $text = $Block['element']['text']['text']; |
|
344 | - |
|
345 | - $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
346 | - |
|
347 | - $Block['element']['text']['text'] = $text; |
|
348 | - |
|
349 | - return $Block; |
|
350 | - } |
|
351 | - |
|
352 | - # |
|
353 | - # Comment |
|
354 | - |
|
355 | - protected function blockComment($Line) |
|
356 | - { |
|
357 | - if ($this->markupEscaped) |
|
358 | - { |
|
359 | - return; |
|
360 | - } |
|
361 | - |
|
362 | - if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') |
|
363 | - { |
|
364 | - $Block = array( |
|
365 | - 'markup' => $Line['body'], |
|
366 | - ); |
|
367 | - |
|
368 | - if (preg_match('/-->$/', $Line['text'])) |
|
369 | - { |
|
370 | - $Block['closed'] = true; |
|
371 | - } |
|
372 | - |
|
373 | - return $Block; |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - protected function blockCommentContinue($Line, array $Block) |
|
378 | - { |
|
379 | - if (isset($Block['closed'])) |
|
380 | - { |
|
381 | - return; |
|
382 | - } |
|
383 | - |
|
384 | - $Block['markup'] .= "\n" . $Line['body']; |
|
385 | - |
|
386 | - if (preg_match('/-->$/', $Line['text'])) |
|
387 | - { |
|
388 | - $Block['closed'] = true; |
|
389 | - } |
|
390 | - |
|
391 | - return $Block; |
|
392 | - } |
|
393 | - |
|
394 | - # |
|
395 | - # Fenced Code |
|
396 | - |
|
397 | - protected function blockFencedCode($Line) |
|
398 | - { |
|
399 | - if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches)) |
|
400 | - { |
|
401 | - $Element = array( |
|
402 | - 'name' => 'code', |
|
403 | - 'text' => '', |
|
404 | - ); |
|
405 | - |
|
406 | - if (isset($matches[1])) |
|
407 | - { |
|
408 | - $class = 'language-'.$matches[1]; |
|
409 | - |
|
410 | - $Element['attributes'] = array( |
|
411 | - 'class' => $class, |
|
412 | - ); |
|
413 | - } |
|
414 | - |
|
415 | - $Block = array( |
|
416 | - 'char' => $Line['text'][0], |
|
417 | - 'element' => array( |
|
418 | - 'name' => 'pre', |
|
419 | - 'handler' => 'element', |
|
420 | - 'text' => $Element, |
|
421 | - ), |
|
422 | - ); |
|
423 | - |
|
424 | - return $Block; |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - protected function blockFencedCodeContinue($Line, $Block) |
|
429 | - { |
|
430 | - if (isset($Block['complete'])) |
|
431 | - { |
|
432 | - return; |
|
433 | - } |
|
434 | - |
|
435 | - if (isset($Block['interrupted'])) |
|
436 | - { |
|
437 | - $Block['element']['text']['text'] .= "\n"; |
|
438 | - |
|
439 | - unset($Block['interrupted']); |
|
440 | - } |
|
441 | - |
|
442 | - if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text'])) |
|
443 | - { |
|
444 | - $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1); |
|
445 | - |
|
446 | - $Block['complete'] = true; |
|
447 | - |
|
448 | - return $Block; |
|
449 | - } |
|
450 | - |
|
451 | - $Block['element']['text']['text'] .= "\n".$Line['body'];; |
|
452 | - |
|
453 | - return $Block; |
|
454 | - } |
|
455 | - |
|
456 | - protected function blockFencedCodeComplete($Block) |
|
457 | - { |
|
458 | - $text = $Block['element']['text']['text']; |
|
459 | - |
|
460 | - $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
461 | - |
|
462 | - $Block['element']['text']['text'] = $text; |
|
463 | - |
|
464 | - return $Block; |
|
465 | - } |
|
466 | - |
|
467 | - # |
|
468 | - # Header |
|
469 | - |
|
470 | - protected function blockHeader($Line) |
|
471 | - { |
|
472 | - if (isset($Line['text'][1])) |
|
473 | - { |
|
474 | - $level = 1; |
|
475 | - |
|
476 | - while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') |
|
477 | - { |
|
478 | - $level ++; |
|
479 | - } |
|
480 | - |
|
481 | - if ($level > 6) |
|
482 | - { |
|
483 | - return; |
|
484 | - } |
|
485 | - |
|
486 | - $text = trim($Line['text'], '# '); |
|
487 | - |
|
488 | - $Block = array( |
|
489 | - 'element' => array( |
|
490 | - 'name' => 'h' . min(6, $level), |
|
491 | - 'text' => $text, |
|
492 | - 'handler' => 'line', |
|
493 | - ), |
|
494 | - ); |
|
495 | - |
|
496 | - return $Block; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - # |
|
501 | - # List |
|
502 | - |
|
503 | - protected function blockList($Line) |
|
504 | - { |
|
505 | - list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); |
|
506 | - |
|
507 | - if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) |
|
508 | - { |
|
509 | - $Block = array( |
|
510 | - 'indent' => $Line['indent'], |
|
511 | - 'pattern' => $pattern, |
|
512 | - 'element' => array( |
|
513 | - 'name' => $name, |
|
514 | - 'handler' => 'elements', |
|
515 | - ), |
|
516 | - ); |
|
517 | - |
|
518 | - $Block['li'] = array( |
|
519 | - 'name' => 'li', |
|
520 | - 'handler' => 'li', |
|
521 | - 'text' => array( |
|
522 | - $matches[2], |
|
523 | - ), |
|
524 | - ); |
|
525 | - |
|
526 | - $Block['element']['text'] []= & $Block['li']; |
|
316 | + return $Block; |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + protected function blockCodeContinue($Line, $Block) |
|
321 | + { |
|
322 | + if ($Line['indent'] >= 4) |
|
323 | + { |
|
324 | + if (isset($Block['interrupted'])) |
|
325 | + { |
|
326 | + $Block['element']['text']['text'] .= "\n"; |
|
327 | + |
|
328 | + unset($Block['interrupted']); |
|
329 | + } |
|
330 | + |
|
331 | + $Block['element']['text']['text'] .= "\n"; |
|
332 | + |
|
333 | + $text = substr($Line['body'], 4); |
|
334 | + |
|
335 | + $Block['element']['text']['text'] .= $text; |
|
336 | + |
|
337 | + return $Block; |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + protected function blockCodeComplete($Block) |
|
342 | + { |
|
343 | + $text = $Block['element']['text']['text']; |
|
344 | + |
|
345 | + $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
346 | + |
|
347 | + $Block['element']['text']['text'] = $text; |
|
348 | + |
|
349 | + return $Block; |
|
350 | + } |
|
351 | + |
|
352 | + # |
|
353 | + # Comment |
|
354 | + |
|
355 | + protected function blockComment($Line) |
|
356 | + { |
|
357 | + if ($this->markupEscaped) |
|
358 | + { |
|
359 | + return; |
|
360 | + } |
|
361 | + |
|
362 | + if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') |
|
363 | + { |
|
364 | + $Block = array( |
|
365 | + 'markup' => $Line['body'], |
|
366 | + ); |
|
367 | + |
|
368 | + if (preg_match('/-->$/', $Line['text'])) |
|
369 | + { |
|
370 | + $Block['closed'] = true; |
|
371 | + } |
|
372 | + |
|
373 | + return $Block; |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + protected function blockCommentContinue($Line, array $Block) |
|
378 | + { |
|
379 | + if (isset($Block['closed'])) |
|
380 | + { |
|
381 | + return; |
|
382 | + } |
|
383 | + |
|
384 | + $Block['markup'] .= "\n" . $Line['body']; |
|
385 | + |
|
386 | + if (preg_match('/-->$/', $Line['text'])) |
|
387 | + { |
|
388 | + $Block['closed'] = true; |
|
389 | + } |
|
390 | + |
|
391 | + return $Block; |
|
392 | + } |
|
393 | + |
|
394 | + # |
|
395 | + # Fenced Code |
|
396 | + |
|
397 | + protected function blockFencedCode($Line) |
|
398 | + { |
|
399 | + if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches)) |
|
400 | + { |
|
401 | + $Element = array( |
|
402 | + 'name' => 'code', |
|
403 | + 'text' => '', |
|
404 | + ); |
|
405 | + |
|
406 | + if (isset($matches[1])) |
|
407 | + { |
|
408 | + $class = 'language-'.$matches[1]; |
|
409 | + |
|
410 | + $Element['attributes'] = array( |
|
411 | + 'class' => $class, |
|
412 | + ); |
|
413 | + } |
|
414 | + |
|
415 | + $Block = array( |
|
416 | + 'char' => $Line['text'][0], |
|
417 | + 'element' => array( |
|
418 | + 'name' => 'pre', |
|
419 | + 'handler' => 'element', |
|
420 | + 'text' => $Element, |
|
421 | + ), |
|
422 | + ); |
|
423 | + |
|
424 | + return $Block; |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + protected function blockFencedCodeContinue($Line, $Block) |
|
429 | + { |
|
430 | + if (isset($Block['complete'])) |
|
431 | + { |
|
432 | + return; |
|
433 | + } |
|
434 | + |
|
435 | + if (isset($Block['interrupted'])) |
|
436 | + { |
|
437 | + $Block['element']['text']['text'] .= "\n"; |
|
438 | + |
|
439 | + unset($Block['interrupted']); |
|
440 | + } |
|
441 | + |
|
442 | + if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text'])) |
|
443 | + { |
|
444 | + $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1); |
|
445 | + |
|
446 | + $Block['complete'] = true; |
|
447 | + |
|
448 | + return $Block; |
|
449 | + } |
|
450 | + |
|
451 | + $Block['element']['text']['text'] .= "\n".$Line['body'];; |
|
452 | + |
|
453 | + return $Block; |
|
454 | + } |
|
455 | + |
|
456 | + protected function blockFencedCodeComplete($Block) |
|
457 | + { |
|
458 | + $text = $Block['element']['text']['text']; |
|
459 | + |
|
460 | + $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
461 | + |
|
462 | + $Block['element']['text']['text'] = $text; |
|
463 | + |
|
464 | + return $Block; |
|
465 | + } |
|
466 | + |
|
467 | + # |
|
468 | + # Header |
|
469 | + |
|
470 | + protected function blockHeader($Line) |
|
471 | + { |
|
472 | + if (isset($Line['text'][1])) |
|
473 | + { |
|
474 | + $level = 1; |
|
475 | + |
|
476 | + while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') |
|
477 | + { |
|
478 | + $level ++; |
|
479 | + } |
|
480 | + |
|
481 | + if ($level > 6) |
|
482 | + { |
|
483 | + return; |
|
484 | + } |
|
485 | + |
|
486 | + $text = trim($Line['text'], '# '); |
|
487 | + |
|
488 | + $Block = array( |
|
489 | + 'element' => array( |
|
490 | + 'name' => 'h' . min(6, $level), |
|
491 | + 'text' => $text, |
|
492 | + 'handler' => 'line', |
|
493 | + ), |
|
494 | + ); |
|
495 | + |
|
496 | + return $Block; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + # |
|
501 | + # List |
|
502 | + |
|
503 | + protected function blockList($Line) |
|
504 | + { |
|
505 | + list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); |
|
506 | + |
|
507 | + if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) |
|
508 | + { |
|
509 | + $Block = array( |
|
510 | + 'indent' => $Line['indent'], |
|
511 | + 'pattern' => $pattern, |
|
512 | + 'element' => array( |
|
513 | + 'name' => $name, |
|
514 | + 'handler' => 'elements', |
|
515 | + ), |
|
516 | + ); |
|
517 | + |
|
518 | + $Block['li'] = array( |
|
519 | + 'name' => 'li', |
|
520 | + 'handler' => 'li', |
|
521 | + 'text' => array( |
|
522 | + $matches[2], |
|
523 | + ), |
|
524 | + ); |
|
525 | + |
|
526 | + $Block['element']['text'] []= & $Block['li']; |
|
527 | 527 | |
528 | - return $Block; |
|
529 | - } |
|
530 | - } |
|
528 | + return $Block; |
|
529 | + } |
|
530 | + } |
|
531 | 531 | |
532 | - protected function blockListContinue($Line, array $Block) |
|
533 | - { |
|
534 | - if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches)) |
|
535 | - { |
|
536 | - if (isset($Block['interrupted'])) |
|
537 | - { |
|
538 | - $Block['li']['text'] []= ''; |
|
539 | - |
|
540 | - unset($Block['interrupted']); |
|
541 | - } |
|
542 | - |
|
543 | - unset($Block['li']); |
|
544 | - |
|
545 | - $text = isset($matches[1]) ? $matches[1] : ''; |
|
546 | - |
|
547 | - $Block['li'] = array( |
|
548 | - 'name' => 'li', |
|
549 | - 'handler' => 'li', |
|
550 | - 'text' => array( |
|
551 | - $text, |
|
552 | - ), |
|
553 | - ); |
|
554 | - |
|
555 | - $Block['element']['text'] []= & $Block['li']; |
|
556 | - |
|
557 | - return $Block; |
|
558 | - } |
|
559 | - |
|
560 | - if ($Line['text'][0] === '[' and $this->blockReference($Line)) |
|
561 | - { |
|
562 | - return $Block; |
|
563 | - } |
|
564 | - |
|
565 | - if ( ! isset($Block['interrupted'])) |
|
566 | - { |
|
567 | - $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
|
568 | - |
|
569 | - $Block['li']['text'] []= $text; |
|
570 | - |
|
571 | - return $Block; |
|
572 | - } |
|
573 | - |
|
574 | - if ($Line['indent'] > 0) |
|
575 | - { |
|
576 | - $Block['li']['text'] []= ''; |
|
577 | - |
|
578 | - $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
|
579 | - |
|
580 | - $Block['li']['text'] []= $text; |
|
581 | - |
|
582 | - unset($Block['interrupted']); |
|
583 | - |
|
584 | - return $Block; |
|
585 | - } |
|
586 | - } |
|
587 | - |
|
588 | - # |
|
589 | - # Quote |
|
590 | - |
|
591 | - protected function blockQuote($Line) |
|
592 | - { |
|
593 | - if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) |
|
594 | - { |
|
595 | - $Block = array( |
|
596 | - 'element' => array( |
|
597 | - 'name' => 'blockquote', |
|
598 | - 'handler' => 'lines', |
|
599 | - 'text' => (array) $matches[1], |
|
600 | - ), |
|
601 | - ); |
|
602 | - |
|
603 | - return $Block; |
|
604 | - } |
|
605 | - } |
|
606 | - |
|
607 | - protected function blockQuoteContinue($Line, array $Block) |
|
608 | - { |
|
609 | - if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) |
|
610 | - { |
|
611 | - if (isset($Block['interrupted'])) |
|
612 | - { |
|
613 | - $Block['element']['text'] []= ''; |
|
614 | - |
|
615 | - unset($Block['interrupted']); |
|
616 | - } |
|
617 | - |
|
618 | - $Block['element']['text'] []= $matches[1]; |
|
619 | - |
|
620 | - return $Block; |
|
621 | - } |
|
622 | - |
|
623 | - if ( ! isset($Block['interrupted'])) |
|
624 | - { |
|
625 | - $Block['element']['text'] []= $Line['text']; |
|
626 | - |
|
627 | - return $Block; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - # |
|
632 | - # Rule |
|
633 | - |
|
634 | - protected function blockRule($Line) |
|
635 | - { |
|
636 | - if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text'])) |
|
637 | - { |
|
638 | - $Block = array( |
|
639 | - 'element' => array( |
|
640 | - 'name' => 'hr' |
|
641 | - ), |
|
642 | - ); |
|
643 | - |
|
644 | - return $Block; |
|
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - # |
|
649 | - # Setext |
|
650 | - |
|
651 | - protected function blockSetextHeader($Line, array $Block = null) |
|
652 | - { |
|
653 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
654 | - { |
|
655 | - return; |
|
656 | - } |
|
657 | - |
|
658 | - if (chop($Line['text'], $Line['text'][0]) === '') |
|
659 | - { |
|
660 | - $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; |
|
661 | - |
|
662 | - return $Block; |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - # |
|
667 | - # Markup |
|
668 | - |
|
669 | - protected function blockMarkup($Line) |
|
670 | - { |
|
671 | - if ($this->markupEscaped) |
|
672 | - { |
|
673 | - return; |
|
674 | - } |
|
675 | - |
|
676 | - if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) |
|
677 | - { |
|
678 | - $element = strtolower($matches[1]); |
|
679 | - |
|
680 | - if (in_array($element, $this->textLevelElements)) |
|
681 | - { |
|
682 | - return; |
|
683 | - } |
|
684 | - |
|
685 | - $Block = array( |
|
686 | - 'name' => $matches[1], |
|
687 | - 'depth' => 0, |
|
688 | - 'markup' => $Line['text'], |
|
689 | - ); |
|
690 | - |
|
691 | - $length = strlen($matches[0]); |
|
692 | - |
|
693 | - $remainder = substr($Line['text'], $length); |
|
694 | - |
|
695 | - if (trim($remainder) === '') |
|
696 | - { |
|
697 | - if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
|
698 | - { |
|
699 | - $Block['closed'] = true; |
|
700 | - |
|
701 | - $Block['void'] = true; |
|
702 | - } |
|
703 | - } |
|
704 | - else |
|
705 | - { |
|
706 | - if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
|
707 | - { |
|
708 | - return; |
|
709 | - } |
|
710 | - |
|
711 | - if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder)) |
|
712 | - { |
|
713 | - $Block['closed'] = true; |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - return $Block; |
|
718 | - } |
|
719 | - } |
|
720 | - |
|
721 | - protected function blockMarkupContinue($Line, array $Block) |
|
722 | - { |
|
723 | - if (isset($Block['closed'])) |
|
724 | - { |
|
725 | - return; |
|
726 | - } |
|
727 | - |
|
728 | - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
729 | - { |
|
730 | - $Block['depth'] ++; |
|
731 | - } |
|
732 | - |
|
733 | - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
734 | - { |
|
735 | - if ($Block['depth'] > 0) |
|
736 | - { |
|
737 | - $Block['depth'] --; |
|
738 | - } |
|
739 | - else |
|
740 | - { |
|
741 | - $Block['closed'] = true; |
|
742 | - } |
|
743 | - } |
|
744 | - |
|
745 | - if (isset($Block['interrupted'])) |
|
746 | - { |
|
747 | - $Block['markup'] .= "\n"; |
|
748 | - |
|
749 | - unset($Block['interrupted']); |
|
750 | - } |
|
751 | - |
|
752 | - $Block['markup'] .= "\n".$Line['body']; |
|
753 | - |
|
754 | - return $Block; |
|
755 | - } |
|
756 | - |
|
757 | - # |
|
758 | - # Reference |
|
759 | - |
|
760 | - protected function blockReference($Line) |
|
761 | - { |
|
762 | - if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches)) |
|
763 | - { |
|
764 | - $id = strtolower($matches[1]); |
|
765 | - |
|
766 | - $Data = array( |
|
767 | - 'url' => $matches[2], |
|
768 | - 'title' => null, |
|
769 | - ); |
|
770 | - |
|
771 | - if (isset($matches[3])) |
|
772 | - { |
|
773 | - $Data['title'] = $matches[3]; |
|
774 | - } |
|
775 | - |
|
776 | - $this->DefinitionData['Reference'][$id] = $Data; |
|
777 | - |
|
778 | - $Block = array( |
|
779 | - 'hidden' => true, |
|
780 | - ); |
|
781 | - |
|
782 | - return $Block; |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - # |
|
787 | - # Table |
|
788 | - |
|
789 | - protected function blockTable($Line, array $Block = null) |
|
790 | - { |
|
791 | - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
792 | - { |
|
793 | - return; |
|
794 | - } |
|
795 | - |
|
796 | - if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '') |
|
797 | - { |
|
798 | - $alignments = array(); |
|
799 | - |
|
800 | - $divider = $Line['text']; |
|
801 | - |
|
802 | - $divider = trim($divider); |
|
803 | - $divider = trim($divider, '|'); |
|
804 | - |
|
805 | - $dividerCells = explode('|', $divider); |
|
806 | - |
|
807 | - foreach ($dividerCells as $dividerCell) |
|
808 | - { |
|
809 | - $dividerCell = trim($dividerCell); |
|
810 | - |
|
811 | - if ($dividerCell === '') |
|
812 | - { |
|
813 | - continue; |
|
814 | - } |
|
815 | - |
|
816 | - $alignment = null; |
|
817 | - |
|
818 | - if ($dividerCell[0] === ':') |
|
819 | - { |
|
820 | - $alignment = 'left'; |
|
821 | - } |
|
822 | - |
|
823 | - if (substr($dividerCell, - 1) === ':') |
|
824 | - { |
|
825 | - $alignment = $alignment === 'left' ? 'center' : 'right'; |
|
826 | - } |
|
827 | - |
|
828 | - $alignments []= $alignment; |
|
829 | - } |
|
830 | - |
|
831 | - # ~ |
|
832 | - |
|
833 | - $HeaderElements = array(); |
|
834 | - |
|
835 | - $header = $Block['element']['text']; |
|
836 | - |
|
837 | - $header = trim($header); |
|
838 | - $header = trim($header, '|'); |
|
532 | + protected function blockListContinue($Line, array $Block) |
|
533 | + { |
|
534 | + if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches)) |
|
535 | + { |
|
536 | + if (isset($Block['interrupted'])) |
|
537 | + { |
|
538 | + $Block['li']['text'] []= ''; |
|
539 | + |
|
540 | + unset($Block['interrupted']); |
|
541 | + } |
|
542 | + |
|
543 | + unset($Block['li']); |
|
544 | + |
|
545 | + $text = isset($matches[1]) ? $matches[1] : ''; |
|
546 | + |
|
547 | + $Block['li'] = array( |
|
548 | + 'name' => 'li', |
|
549 | + 'handler' => 'li', |
|
550 | + 'text' => array( |
|
551 | + $text, |
|
552 | + ), |
|
553 | + ); |
|
554 | + |
|
555 | + $Block['element']['text'] []= & $Block['li']; |
|
556 | + |
|
557 | + return $Block; |
|
558 | + } |
|
559 | + |
|
560 | + if ($Line['text'][0] === '[' and $this->blockReference($Line)) |
|
561 | + { |
|
562 | + return $Block; |
|
563 | + } |
|
564 | + |
|
565 | + if ( ! isset($Block['interrupted'])) |
|
566 | + { |
|
567 | + $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
|
568 | + |
|
569 | + $Block['li']['text'] []= $text; |
|
570 | + |
|
571 | + return $Block; |
|
572 | + } |
|
573 | + |
|
574 | + if ($Line['indent'] > 0) |
|
575 | + { |
|
576 | + $Block['li']['text'] []= ''; |
|
577 | + |
|
578 | + $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); |
|
579 | + |
|
580 | + $Block['li']['text'] []= $text; |
|
581 | + |
|
582 | + unset($Block['interrupted']); |
|
583 | + |
|
584 | + return $Block; |
|
585 | + } |
|
586 | + } |
|
587 | + |
|
588 | + # |
|
589 | + # Quote |
|
590 | + |
|
591 | + protected function blockQuote($Line) |
|
592 | + { |
|
593 | + if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) |
|
594 | + { |
|
595 | + $Block = array( |
|
596 | + 'element' => array( |
|
597 | + 'name' => 'blockquote', |
|
598 | + 'handler' => 'lines', |
|
599 | + 'text' => (array) $matches[1], |
|
600 | + ), |
|
601 | + ); |
|
602 | + |
|
603 | + return $Block; |
|
604 | + } |
|
605 | + } |
|
606 | + |
|
607 | + protected function blockQuoteContinue($Line, array $Block) |
|
608 | + { |
|
609 | + if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) |
|
610 | + { |
|
611 | + if (isset($Block['interrupted'])) |
|
612 | + { |
|
613 | + $Block['element']['text'] []= ''; |
|
614 | + |
|
615 | + unset($Block['interrupted']); |
|
616 | + } |
|
617 | + |
|
618 | + $Block['element']['text'] []= $matches[1]; |
|
619 | + |
|
620 | + return $Block; |
|
621 | + } |
|
622 | + |
|
623 | + if ( ! isset($Block['interrupted'])) |
|
624 | + { |
|
625 | + $Block['element']['text'] []= $Line['text']; |
|
626 | + |
|
627 | + return $Block; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + # |
|
632 | + # Rule |
|
633 | + |
|
634 | + protected function blockRule($Line) |
|
635 | + { |
|
636 | + if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text'])) |
|
637 | + { |
|
638 | + $Block = array( |
|
639 | + 'element' => array( |
|
640 | + 'name' => 'hr' |
|
641 | + ), |
|
642 | + ); |
|
643 | + |
|
644 | + return $Block; |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + # |
|
649 | + # Setext |
|
650 | + |
|
651 | + protected function blockSetextHeader($Line, array $Block = null) |
|
652 | + { |
|
653 | + if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
654 | + { |
|
655 | + return; |
|
656 | + } |
|
657 | + |
|
658 | + if (chop($Line['text'], $Line['text'][0]) === '') |
|
659 | + { |
|
660 | + $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; |
|
661 | + |
|
662 | + return $Block; |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + # |
|
667 | + # Markup |
|
668 | + |
|
669 | + protected function blockMarkup($Line) |
|
670 | + { |
|
671 | + if ($this->markupEscaped) |
|
672 | + { |
|
673 | + return; |
|
674 | + } |
|
675 | + |
|
676 | + if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) |
|
677 | + { |
|
678 | + $element = strtolower($matches[1]); |
|
679 | + |
|
680 | + if (in_array($element, $this->textLevelElements)) |
|
681 | + { |
|
682 | + return; |
|
683 | + } |
|
684 | + |
|
685 | + $Block = array( |
|
686 | + 'name' => $matches[1], |
|
687 | + 'depth' => 0, |
|
688 | + 'markup' => $Line['text'], |
|
689 | + ); |
|
690 | + |
|
691 | + $length = strlen($matches[0]); |
|
692 | + |
|
693 | + $remainder = substr($Line['text'], $length); |
|
694 | + |
|
695 | + if (trim($remainder) === '') |
|
696 | + { |
|
697 | + if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
|
698 | + { |
|
699 | + $Block['closed'] = true; |
|
700 | + |
|
701 | + $Block['void'] = true; |
|
702 | + } |
|
703 | + } |
|
704 | + else |
|
705 | + { |
|
706 | + if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
|
707 | + { |
|
708 | + return; |
|
709 | + } |
|
710 | + |
|
711 | + if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder)) |
|
712 | + { |
|
713 | + $Block['closed'] = true; |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + return $Block; |
|
718 | + } |
|
719 | + } |
|
720 | + |
|
721 | + protected function blockMarkupContinue($Line, array $Block) |
|
722 | + { |
|
723 | + if (isset($Block['closed'])) |
|
724 | + { |
|
725 | + return; |
|
726 | + } |
|
727 | + |
|
728 | + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
729 | + { |
|
730 | + $Block['depth'] ++; |
|
731 | + } |
|
732 | + |
|
733 | + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
734 | + { |
|
735 | + if ($Block['depth'] > 0) |
|
736 | + { |
|
737 | + $Block['depth'] --; |
|
738 | + } |
|
739 | + else |
|
740 | + { |
|
741 | + $Block['closed'] = true; |
|
742 | + } |
|
743 | + } |
|
744 | + |
|
745 | + if (isset($Block['interrupted'])) |
|
746 | + { |
|
747 | + $Block['markup'] .= "\n"; |
|
748 | + |
|
749 | + unset($Block['interrupted']); |
|
750 | + } |
|
751 | + |
|
752 | + $Block['markup'] .= "\n".$Line['body']; |
|
753 | + |
|
754 | + return $Block; |
|
755 | + } |
|
756 | + |
|
757 | + # |
|
758 | + # Reference |
|
759 | + |
|
760 | + protected function blockReference($Line) |
|
761 | + { |
|
762 | + if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches)) |
|
763 | + { |
|
764 | + $id = strtolower($matches[1]); |
|
765 | + |
|
766 | + $Data = array( |
|
767 | + 'url' => $matches[2], |
|
768 | + 'title' => null, |
|
769 | + ); |
|
770 | + |
|
771 | + if (isset($matches[3])) |
|
772 | + { |
|
773 | + $Data['title'] = $matches[3]; |
|
774 | + } |
|
775 | + |
|
776 | + $this->DefinitionData['Reference'][$id] = $Data; |
|
777 | + |
|
778 | + $Block = array( |
|
779 | + 'hidden' => true, |
|
780 | + ); |
|
781 | + |
|
782 | + return $Block; |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + # |
|
787 | + # Table |
|
788 | + |
|
789 | + protected function blockTable($Line, array $Block = null) |
|
790 | + { |
|
791 | + if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) |
|
792 | + { |
|
793 | + return; |
|
794 | + } |
|
795 | + |
|
796 | + if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '') |
|
797 | + { |
|
798 | + $alignments = array(); |
|
799 | + |
|
800 | + $divider = $Line['text']; |
|
801 | + |
|
802 | + $divider = trim($divider); |
|
803 | + $divider = trim($divider, '|'); |
|
804 | + |
|
805 | + $dividerCells = explode('|', $divider); |
|
806 | + |
|
807 | + foreach ($dividerCells as $dividerCell) |
|
808 | + { |
|
809 | + $dividerCell = trim($dividerCell); |
|
810 | + |
|
811 | + if ($dividerCell === '') |
|
812 | + { |
|
813 | + continue; |
|
814 | + } |
|
815 | + |
|
816 | + $alignment = null; |
|
817 | + |
|
818 | + if ($dividerCell[0] === ':') |
|
819 | + { |
|
820 | + $alignment = 'left'; |
|
821 | + } |
|
822 | + |
|
823 | + if (substr($dividerCell, - 1) === ':') |
|
824 | + { |
|
825 | + $alignment = $alignment === 'left' ? 'center' : 'right'; |
|
826 | + } |
|
827 | + |
|
828 | + $alignments []= $alignment; |
|
829 | + } |
|
830 | + |
|
831 | + # ~ |
|
832 | + |
|
833 | + $HeaderElements = array(); |
|
834 | + |
|
835 | + $header = $Block['element']['text']; |
|
836 | + |
|
837 | + $header = trim($header); |
|
838 | + $header = trim($header, '|'); |
|
839 | 839 | |
840 | - $headerCells = explode('|', $header); |
|
840 | + $headerCells = explode('|', $header); |
|
841 | 841 | |
842 | - foreach ($headerCells as $index => $headerCell) |
|
843 | - { |
|
844 | - $headerCell = trim($headerCell); |
|
842 | + foreach ($headerCells as $index => $headerCell) |
|
843 | + { |
|
844 | + $headerCell = trim($headerCell); |
|
845 | 845 | |
846 | - $HeaderElement = array( |
|
847 | - 'name' => 'th', |
|
848 | - 'text' => $headerCell, |
|
849 | - 'handler' => 'line', |
|
850 | - ); |
|
846 | + $HeaderElement = array( |
|
847 | + 'name' => 'th', |
|
848 | + 'text' => $headerCell, |
|
849 | + 'handler' => 'line', |
|
850 | + ); |
|
851 | 851 | |
852 | - if (isset($alignments[$index])) |
|
853 | - { |
|
854 | - $alignment = $alignments[$index]; |
|
855 | - |
|
856 | - $HeaderElement['attributes'] = array( |
|
857 | - 'style' => 'text-align: '.$alignment.';', |
|
858 | - ); |
|
859 | - } |
|
860 | - |
|
861 | - $HeaderElements []= $HeaderElement; |
|
862 | - } |
|
863 | - |
|
864 | - # ~ |
|
865 | - |
|
866 | - $Block = array( |
|
867 | - 'alignments' => $alignments, |
|
868 | - 'identified' => true, |
|
869 | - 'element' => array( |
|
870 | - 'name' => 'table', |
|
871 | - 'handler' => 'elements', |
|
872 | - ), |
|
873 | - ); |
|
874 | - |
|
875 | - $Block['element']['text'] []= array( |
|
876 | - 'name' => 'thead', |
|
877 | - 'handler' => 'elements', |
|
878 | - ); |
|
879 | - |
|
880 | - $Block['element']['text'] []= array( |
|
881 | - 'name' => 'tbody', |
|
882 | - 'handler' => 'elements', |
|
883 | - 'text' => array(), |
|
884 | - ); |
|
885 | - |
|
886 | - $Block['element']['text'][0]['text'] []= array( |
|
887 | - 'name' => 'tr', |
|
888 | - 'handler' => 'elements', |
|
889 | - 'text' => $HeaderElements, |
|
890 | - ); |
|
891 | - |
|
892 | - return $Block; |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - protected function blockTableContinue($Line, array $Block) |
|
897 | - { |
|
898 | - if (isset($Block['interrupted'])) |
|
899 | - { |
|
900 | - return; |
|
901 | - } |
|
902 | - |
|
903 | - if ($Line['text'][0] === '|' or strpos($Line['text'], '|')) |
|
904 | - { |
|
905 | - $Elements = array(); |
|
906 | - |
|
907 | - $row = $Line['text']; |
|
908 | - |
|
909 | - $row = trim($row); |
|
910 | - $row = trim($row, '|'); |
|
911 | - |
|
912 | - preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches); |
|
913 | - |
|
914 | - foreach ($matches[0] as $index => $cell) |
|
915 | - { |
|
916 | - $cell = trim($cell); |
|
917 | - |
|
918 | - $Element = array( |
|
919 | - 'name' => 'td', |
|
920 | - 'handler' => 'line', |
|
921 | - 'text' => $cell, |
|
922 | - ); |
|
923 | - |
|
924 | - if (isset($Block['alignments'][$index])) |
|
925 | - { |
|
926 | - $Element['attributes'] = array( |
|
927 | - 'style' => 'text-align: '.$Block['alignments'][$index].';', |
|
928 | - ); |
|
929 | - } |
|
930 | - |
|
931 | - $Elements []= $Element; |
|
932 | - } |
|
933 | - |
|
934 | - $Element = array( |
|
935 | - 'name' => 'tr', |
|
936 | - 'handler' => 'elements', |
|
937 | - 'text' => $Elements, |
|
938 | - ); |
|
939 | - |
|
940 | - $Block['element']['text'][1]['text'] []= $Element; |
|
941 | - |
|
942 | - return $Block; |
|
943 | - } |
|
944 | - } |
|
945 | - |
|
946 | - # |
|
947 | - # ~ |
|
948 | - # |
|
949 | - |
|
950 | - protected function paragraph($Line) |
|
951 | - { |
|
952 | - $Block = array( |
|
953 | - 'element' => array( |
|
954 | - 'name' => 'p', |
|
955 | - 'text' => $Line['text'], |
|
956 | - 'handler' => 'line', |
|
957 | - ), |
|
958 | - ); |
|
852 | + if (isset($alignments[$index])) |
|
853 | + { |
|
854 | + $alignment = $alignments[$index]; |
|
855 | + |
|
856 | + $HeaderElement['attributes'] = array( |
|
857 | + 'style' => 'text-align: '.$alignment.';', |
|
858 | + ); |
|
859 | + } |
|
860 | + |
|
861 | + $HeaderElements []= $HeaderElement; |
|
862 | + } |
|
863 | + |
|
864 | + # ~ |
|
865 | + |
|
866 | + $Block = array( |
|
867 | + 'alignments' => $alignments, |
|
868 | + 'identified' => true, |
|
869 | + 'element' => array( |
|
870 | + 'name' => 'table', |
|
871 | + 'handler' => 'elements', |
|
872 | + ), |
|
873 | + ); |
|
874 | + |
|
875 | + $Block['element']['text'] []= array( |
|
876 | + 'name' => 'thead', |
|
877 | + 'handler' => 'elements', |
|
878 | + ); |
|
879 | + |
|
880 | + $Block['element']['text'] []= array( |
|
881 | + 'name' => 'tbody', |
|
882 | + 'handler' => 'elements', |
|
883 | + 'text' => array(), |
|
884 | + ); |
|
885 | + |
|
886 | + $Block['element']['text'][0]['text'] []= array( |
|
887 | + 'name' => 'tr', |
|
888 | + 'handler' => 'elements', |
|
889 | + 'text' => $HeaderElements, |
|
890 | + ); |
|
891 | + |
|
892 | + return $Block; |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + protected function blockTableContinue($Line, array $Block) |
|
897 | + { |
|
898 | + if (isset($Block['interrupted'])) |
|
899 | + { |
|
900 | + return; |
|
901 | + } |
|
902 | + |
|
903 | + if ($Line['text'][0] === '|' or strpos($Line['text'], '|')) |
|
904 | + { |
|
905 | + $Elements = array(); |
|
906 | + |
|
907 | + $row = $Line['text']; |
|
908 | + |
|
909 | + $row = trim($row); |
|
910 | + $row = trim($row, '|'); |
|
911 | + |
|
912 | + preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches); |
|
913 | + |
|
914 | + foreach ($matches[0] as $index => $cell) |
|
915 | + { |
|
916 | + $cell = trim($cell); |
|
917 | + |
|
918 | + $Element = array( |
|
919 | + 'name' => 'td', |
|
920 | + 'handler' => 'line', |
|
921 | + 'text' => $cell, |
|
922 | + ); |
|
923 | + |
|
924 | + if (isset($Block['alignments'][$index])) |
|
925 | + { |
|
926 | + $Element['attributes'] = array( |
|
927 | + 'style' => 'text-align: '.$Block['alignments'][$index].';', |
|
928 | + ); |
|
929 | + } |
|
930 | + |
|
931 | + $Elements []= $Element; |
|
932 | + } |
|
933 | + |
|
934 | + $Element = array( |
|
935 | + 'name' => 'tr', |
|
936 | + 'handler' => 'elements', |
|
937 | + 'text' => $Elements, |
|
938 | + ); |
|
939 | + |
|
940 | + $Block['element']['text'][1]['text'] []= $Element; |
|
941 | + |
|
942 | + return $Block; |
|
943 | + } |
|
944 | + } |
|
945 | + |
|
946 | + # |
|
947 | + # ~ |
|
948 | + # |
|
949 | + |
|
950 | + protected function paragraph($Line) |
|
951 | + { |
|
952 | + $Block = array( |
|
953 | + 'element' => array( |
|
954 | + 'name' => 'p', |
|
955 | + 'text' => $Line['text'], |
|
956 | + 'handler' => 'line', |
|
957 | + ), |
|
958 | + ); |
|
959 | 959 | |
960 | - return $Block; |
|
961 | - } |
|
960 | + return $Block; |
|
961 | + } |
|
962 | 962 | |
963 | - # |
|
964 | - # Inline Elements |
|
965 | - # |
|
966 | - |
|
967 | - protected $InlineTypes = array( |
|
968 | - '"' => array('SpecialCharacter'), |
|
969 | - '!' => array('Image'), |
|
970 | - '&' => array('SpecialCharacter'), |
|
971 | - '*' => array('Emphasis'), |
|
972 | - ':' => array('Url'), |
|
973 | - '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'), |
|
974 | - '>' => array('SpecialCharacter'), |
|
975 | - '[' => array('Link'), |
|
976 | - '_' => array('Emphasis'), |
|
977 | - '`' => array('Code'), |
|
978 | - '~' => array('Strikethrough'), |
|
979 | - '\\' => array('EscapeSequence'), |
|
980 | - ); |
|
981 | - |
|
982 | - # ~ |
|
983 | - |
|
984 | - protected $inlineMarkerList = '!"*_&[:<>`~\\'; |
|
963 | + # |
|
964 | + # Inline Elements |
|
965 | + # |
|
966 | + |
|
967 | + protected $InlineTypes = array( |
|
968 | + '"' => array('SpecialCharacter'), |
|
969 | + '!' => array('Image'), |
|
970 | + '&' => array('SpecialCharacter'), |
|
971 | + '*' => array('Emphasis'), |
|
972 | + ':' => array('Url'), |
|
973 | + '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'), |
|
974 | + '>' => array('SpecialCharacter'), |
|
975 | + '[' => array('Link'), |
|
976 | + '_' => array('Emphasis'), |
|
977 | + '`' => array('Code'), |
|
978 | + '~' => array('Strikethrough'), |
|
979 | + '\\' => array('EscapeSequence'), |
|
980 | + ); |
|
981 | + |
|
982 | + # ~ |
|
983 | + |
|
984 | + protected $inlineMarkerList = '!"*_&[:<>`~\\'; |
|
985 | 985 | |
986 | - # |
|
987 | - # ~ |
|
988 | - # |
|
989 | - |
|
990 | - public function line($text) |
|
991 | - { |
|
992 | - $markup = ''; |
|
993 | - |
|
994 | - # $excerpt is based on the first occurrence of a marker |
|
995 | - |
|
996 | - while ($excerpt = strpbrk($text, $this->inlineMarkerList)) |
|
997 | - { |
|
998 | - $marker = $excerpt[0]; |
|
999 | - |
|
1000 | - $markerPosition = strpos($text, $marker); |
|
1001 | - |
|
1002 | - $Excerpt = array('text' => $excerpt, 'context' => $text); |
|
1003 | - |
|
1004 | - foreach ($this->InlineTypes[$marker] as $inlineType) |
|
1005 | - { |
|
1006 | - $Inline = $this->{'inline'.$inlineType}($Excerpt); |
|
1007 | - |
|
1008 | - if ( ! isset($Inline)) |
|
1009 | - { |
|
1010 | - continue; |
|
1011 | - } |
|
1012 | - |
|
1013 | - # makes sure that the inline belongs to "our" marker |
|
1014 | - |
|
1015 | - if (isset($Inline['position']) and $Inline['position'] > $markerPosition) |
|
1016 | - { |
|
1017 | - continue; |
|
1018 | - } |
|
1019 | - |
|
1020 | - # sets a default inline position |
|
1021 | - |
|
1022 | - if ( ! isset($Inline['position'])) |
|
1023 | - { |
|
1024 | - $Inline['position'] = $markerPosition; |
|
1025 | - } |
|
1026 | - |
|
1027 | - # the text that comes before the inline |
|
1028 | - $unmarkedText = substr($text, 0, $Inline['position']); |
|
1029 | - |
|
1030 | - # compile the unmarked text |
|
1031 | - $markup .= $this->unmarkedText($unmarkedText); |
|
1032 | - |
|
1033 | - # compile the inline |
|
1034 | - $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); |
|
1035 | - |
|
1036 | - # remove the examined text |
|
1037 | - $text = substr($text, $Inline['position'] + $Inline['extent']); |
|
1038 | - |
|
1039 | - continue 2; |
|
1040 | - } |
|
1041 | - |
|
1042 | - # the marker does not belong to an inline |
|
1043 | - |
|
1044 | - $unmarkedText = substr($text, 0, $markerPosition + 1); |
|
1045 | - |
|
1046 | - $markup .= $this->unmarkedText($unmarkedText); |
|
1047 | - |
|
1048 | - $text = substr($text, $markerPosition + 1); |
|
1049 | - } |
|
1050 | - |
|
1051 | - $markup .= $this->unmarkedText($text); |
|
1052 | - |
|
1053 | - return $markup; |
|
1054 | - } |
|
1055 | - |
|
1056 | - # |
|
1057 | - # ~ |
|
1058 | - # |
|
1059 | - |
|
1060 | - protected function inlineCode($Excerpt) |
|
1061 | - { |
|
1062 | - $marker = $Excerpt['text'][0]; |
|
1063 | - |
|
1064 | - if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches)) |
|
1065 | - { |
|
1066 | - $text = $matches[2]; |
|
1067 | - $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
1068 | - $text = preg_replace("/[ ]*\n/", ' ', $text); |
|
1069 | - |
|
1070 | - return array( |
|
1071 | - 'extent' => strlen($matches[0]), |
|
1072 | - 'element' => array( |
|
1073 | - 'name' => 'code', |
|
1074 | - 'text' => $text, |
|
1075 | - ), |
|
1076 | - ); |
|
1077 | - } |
|
1078 | - } |
|
1079 | - |
|
1080 | - protected function inlineEmailTag($Excerpt) |
|
1081 | - { |
|
1082 | - if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches)) |
|
1083 | - { |
|
1084 | - $url = $matches[1]; |
|
1085 | - |
|
1086 | - if ( ! isset($matches[2])) |
|
1087 | - { |
|
1088 | - $url = 'mailto:' . $url; |
|
1089 | - } |
|
1090 | - |
|
1091 | - return array( |
|
1092 | - 'extent' => strlen($matches[0]), |
|
1093 | - 'element' => array( |
|
1094 | - 'name' => 'a', |
|
1095 | - 'text' => $matches[1], |
|
1096 | - 'attributes' => array( |
|
1097 | - 'href' => $url, |
|
1098 | - ), |
|
1099 | - ), |
|
1100 | - ); |
|
1101 | - } |
|
1102 | - } |
|
1103 | - |
|
1104 | - protected function inlineEmphasis($Excerpt) |
|
1105 | - { |
|
1106 | - if ( ! isset($Excerpt['text'][1])) |
|
1107 | - { |
|
1108 | - return; |
|
1109 | - } |
|
1110 | - |
|
1111 | - $marker = $Excerpt['text'][0]; |
|
1112 | - |
|
1113 | - if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
|
1114 | - { |
|
1115 | - $emphasis = 'strong'; |
|
1116 | - } |
|
1117 | - elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1118 | - { |
|
1119 | - $emphasis = 'em'; |
|
1120 | - } |
|
1121 | - else |
|
1122 | - { |
|
1123 | - return; |
|
1124 | - } |
|
1125 | - |
|
1126 | - return array( |
|
1127 | - 'extent' => strlen($matches[0]), |
|
1128 | - 'element' => array( |
|
1129 | - 'name' => $emphasis, |
|
1130 | - 'handler' => 'line', |
|
1131 | - 'text' => $matches[1], |
|
1132 | - ), |
|
1133 | - ); |
|
1134 | - } |
|
1135 | - |
|
1136 | - protected function inlineEscapeSequence($Excerpt) |
|
1137 | - { |
|
1138 | - if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) |
|
1139 | - { |
|
1140 | - return array( |
|
1141 | - 'markup' => $Excerpt['text'][1], |
|
1142 | - 'extent' => 2, |
|
1143 | - ); |
|
1144 | - } |
|
1145 | - } |
|
1146 | - |
|
1147 | - protected function inlineImage($Excerpt) |
|
1148 | - { |
|
1149 | - if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1150 | - { |
|
1151 | - return; |
|
1152 | - } |
|
1153 | - |
|
1154 | - $Excerpt['text']= substr($Excerpt['text'], 1); |
|
1155 | - |
|
1156 | - $Link = $this->inlineLink($Excerpt); |
|
1157 | - |
|
1158 | - if ($Link === null) |
|
1159 | - { |
|
1160 | - return; |
|
1161 | - } |
|
1162 | - |
|
1163 | - $Inline = array( |
|
1164 | - 'extent' => $Link['extent'] + 1, |
|
1165 | - 'element' => array( |
|
1166 | - 'name' => 'img', |
|
1167 | - 'attributes' => array( |
|
1168 | - 'src' => $Link['element']['attributes']['href'], |
|
1169 | - 'alt' => $Link['element']['text'], |
|
1170 | - ), |
|
1171 | - ), |
|
1172 | - ); |
|
1173 | - |
|
1174 | - $Inline['element']['attributes'] += $Link['element']['attributes']; |
|
1175 | - |
|
1176 | - unset($Inline['element']['attributes']['href']); |
|
1177 | - |
|
1178 | - return $Inline; |
|
1179 | - } |
|
1180 | - |
|
1181 | - protected function inlineLink($Excerpt) |
|
1182 | - { |
|
1183 | - $Element = array( |
|
1184 | - 'name' => 'a', |
|
1185 | - 'handler' => 'line', |
|
1186 | - 'text' => null, |
|
1187 | - 'attributes' => array( |
|
1188 | - 'href' => null, |
|
1189 | - 'title' => null, |
|
1190 | - ), |
|
1191 | - ); |
|
1192 | - |
|
1193 | - $extent = 0; |
|
1194 | - |
|
1195 | - $remainder = $Excerpt['text']; |
|
1196 | - |
|
1197 | - if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches)) |
|
1198 | - { |
|
1199 | - $Element['text'] = $matches[1]; |
|
1200 | - |
|
1201 | - $extent += strlen($matches[0]); |
|
1202 | - |
|
1203 | - $remainder = substr($remainder, $extent); |
|
1204 | - } |
|
1205 | - else |
|
1206 | - { |
|
1207 | - return; |
|
1208 | - } |
|
1209 | - |
|
1210 | - if (preg_match('/^[(]((?:[^ ()]|[(][^ )]+[)])+)(?:[ ]+("[^"]*"|\'[^\']*\'))?[)]/', $remainder, $matches)) |
|
1211 | - { |
|
1212 | - $Element['attributes']['href'] = $matches[1]; |
|
1213 | - |
|
1214 | - if (isset($matches[2])) |
|
1215 | - { |
|
1216 | - $Element['attributes']['title'] = substr($matches[2], 1, - 1); |
|
1217 | - } |
|
1218 | - |
|
1219 | - $extent += strlen($matches[0]); |
|
1220 | - } |
|
1221 | - else |
|
1222 | - { |
|
1223 | - if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
|
1224 | - { |
|
1225 | - $definition = strlen($matches[1]) ? $matches[1] : $Element['text']; |
|
1226 | - $definition = strtolower($definition); |
|
1227 | - |
|
1228 | - $extent += strlen($matches[0]); |
|
1229 | - } |
|
1230 | - else |
|
1231 | - { |
|
1232 | - $definition = strtolower($Element['text']); |
|
1233 | - } |
|
1234 | - |
|
1235 | - if ( ! isset($this->DefinitionData['Reference'][$definition])) |
|
1236 | - { |
|
1237 | - return; |
|
1238 | - } |
|
1239 | - |
|
1240 | - $Definition = $this->DefinitionData['Reference'][$definition]; |
|
1241 | - |
|
1242 | - $Element['attributes']['href'] = $Definition['url']; |
|
1243 | - $Element['attributes']['title'] = $Definition['title']; |
|
1244 | - } |
|
1245 | - |
|
1246 | - $Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']); |
|
1247 | - |
|
1248 | - return array( |
|
1249 | - 'extent' => $extent, |
|
1250 | - 'element' => $Element, |
|
1251 | - ); |
|
1252 | - } |
|
1253 | - |
|
1254 | - protected function inlineMarkup($Excerpt) |
|
1255 | - { |
|
1256 | - if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false) |
|
1257 | - { |
|
1258 | - return; |
|
1259 | - } |
|
1260 | - |
|
1261 | - if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches)) |
|
1262 | - { |
|
1263 | - return array( |
|
1264 | - 'markup' => $matches[0], |
|
1265 | - 'extent' => strlen($matches[0]), |
|
1266 | - ); |
|
1267 | - } |
|
1268 | - |
|
1269 | - if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches)) |
|
1270 | - { |
|
1271 | - return array( |
|
1272 | - 'markup' => $matches[0], |
|
1273 | - 'extent' => strlen($matches[0]), |
|
1274 | - ); |
|
1275 | - } |
|
1276 | - |
|
1277 | - if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches)) |
|
1278 | - { |
|
1279 | - return array( |
|
1280 | - 'markup' => $matches[0], |
|
1281 | - 'extent' => strlen($matches[0]), |
|
1282 | - ); |
|
1283 | - } |
|
1284 | - } |
|
1285 | - |
|
1286 | - protected function inlineSpecialCharacter($Excerpt) |
|
1287 | - { |
|
1288 | - if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1289 | - { |
|
1290 | - return array( |
|
1291 | - 'markup' => '&', |
|
1292 | - 'extent' => 1, |
|
1293 | - ); |
|
1294 | - } |
|
1295 | - |
|
1296 | - $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); |
|
1297 | - |
|
1298 | - if (isset($SpecialCharacter[$Excerpt['text'][0]])) |
|
1299 | - { |
|
1300 | - return array( |
|
1301 | - 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';', |
|
1302 | - 'extent' => 1, |
|
1303 | - ); |
|
1304 | - } |
|
1305 | - } |
|
1306 | - |
|
1307 | - protected function inlineStrikethrough($Excerpt) |
|
1308 | - { |
|
1309 | - if ( ! isset($Excerpt['text'][1])) |
|
1310 | - { |
|
1311 | - return; |
|
1312 | - } |
|
1313 | - |
|
1314 | - if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) |
|
1315 | - { |
|
1316 | - return array( |
|
1317 | - 'extent' => strlen($matches[0]), |
|
1318 | - 'element' => array( |
|
1319 | - 'name' => 'del', |
|
1320 | - 'text' => $matches[1], |
|
1321 | - 'handler' => 'line', |
|
1322 | - ), |
|
1323 | - ); |
|
1324 | - } |
|
1325 | - } |
|
1326 | - |
|
1327 | - protected function inlineUrl($Excerpt) |
|
1328 | - { |
|
1329 | - if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1330 | - { |
|
1331 | - return; |
|
1332 | - } |
|
1333 | - |
|
1334 | - if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) |
|
1335 | - { |
|
1336 | - $Inline = array( |
|
1337 | - 'extent' => strlen($matches[0][0]), |
|
1338 | - 'position' => $matches[0][1], |
|
1339 | - 'element' => array( |
|
1340 | - 'name' => 'a', |
|
1341 | - 'text' => $matches[0][0], |
|
1342 | - 'attributes' => array( |
|
1343 | - 'href' => $matches[0][0], |
|
1344 | - ), |
|
1345 | - ), |
|
1346 | - ); |
|
1347 | - |
|
1348 | - return $Inline; |
|
1349 | - } |
|
1350 | - } |
|
1351 | - |
|
1352 | - protected function inlineUrlTag($Excerpt) |
|
1353 | - { |
|
1354 | - if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) |
|
1355 | - { |
|
1356 | - $url = str_replace(array('&', '<'), array('&', '<'), $matches[1]); |
|
1357 | - |
|
1358 | - return array( |
|
1359 | - 'extent' => strlen($matches[0]), |
|
1360 | - 'element' => array( |
|
1361 | - 'name' => 'a', |
|
1362 | - 'text' => $url, |
|
1363 | - 'attributes' => array( |
|
1364 | - 'href' => $url, |
|
1365 | - ), |
|
1366 | - ), |
|
1367 | - ); |
|
1368 | - } |
|
1369 | - } |
|
1370 | - |
|
1371 | - # ~ |
|
1372 | - |
|
1373 | - protected function unmarkedText($text) |
|
1374 | - { |
|
1375 | - if ($this->breaksEnabled) |
|
1376 | - { |
|
1377 | - $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
|
1378 | - } |
|
1379 | - else |
|
1380 | - { |
|
1381 | - $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
|
1382 | - $text = str_replace(" \n", "\n", $text); |
|
1383 | - } |
|
1384 | - |
|
1385 | - return $text; |
|
1386 | - } |
|
1387 | - |
|
1388 | - # |
|
1389 | - # Handlers |
|
1390 | - # |
|
1391 | - |
|
1392 | - protected function element(array $Element) |
|
1393 | - { |
|
1394 | - $markup = '<'.$Element['name']; |
|
1395 | - |
|
1396 | - if (isset($Element['attributes'])) |
|
1397 | - { |
|
1398 | - foreach ($Element['attributes'] as $name => $value) |
|
1399 | - { |
|
1400 | - if ($value === null) |
|
1401 | - { |
|
1402 | - continue; |
|
1403 | - } |
|
1404 | - |
|
1405 | - $markup .= ' '.$name.'="'.$value.'"'; |
|
1406 | - } |
|
1407 | - } |
|
1408 | - |
|
1409 | - if (isset($Element['text'])) |
|
1410 | - { |
|
1411 | - $markup .= '>'; |
|
1412 | - |
|
1413 | - if (isset($Element['handler'])) |
|
1414 | - { |
|
1415 | - $markup .= $this->{$Element['handler']}($Element['text']); |
|
1416 | - } |
|
1417 | - else |
|
1418 | - { |
|
1419 | - $markup .= $Element['text']; |
|
1420 | - } |
|
1421 | - |
|
1422 | - $markup .= '</'.$Element['name'].'>'; |
|
1423 | - } |
|
1424 | - else |
|
1425 | - { |
|
1426 | - $markup .= ' />'; |
|
1427 | - } |
|
1428 | - |
|
1429 | - return $markup; |
|
1430 | - } |
|
1431 | - |
|
1432 | - protected function elements(array $Elements) |
|
1433 | - { |
|
1434 | - $markup = ''; |
|
1435 | - |
|
1436 | - foreach ($Elements as $Element) |
|
1437 | - { |
|
1438 | - $markup .= "\n" . $this->element($Element); |
|
1439 | - } |
|
1440 | - |
|
1441 | - $markup .= "\n"; |
|
1442 | - |
|
1443 | - return $markup; |
|
1444 | - } |
|
1445 | - |
|
1446 | - # ~ |
|
1447 | - |
|
1448 | - protected function li($lines) |
|
1449 | - { |
|
1450 | - $markup = $this->lines($lines); |
|
1451 | - |
|
1452 | - $trimmedMarkup = trim($markup); |
|
1453 | - |
|
1454 | - if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1455 | - { |
|
1456 | - $markup = $trimmedMarkup; |
|
1457 | - $markup = substr($markup, 3); |
|
1458 | - |
|
1459 | - $position = strpos($markup, "</p>"); |
|
1460 | - |
|
1461 | - $markup = substr_replace($markup, '', $position, 4); |
|
1462 | - } |
|
1463 | - |
|
1464 | - return $markup; |
|
1465 | - } |
|
1466 | - |
|
1467 | - # |
|
1468 | - # Deprecated Methods |
|
1469 | - # |
|
1470 | - |
|
1471 | - function parse($text) |
|
1472 | - { |
|
1473 | - $markup = $this->text($text); |
|
1474 | - |
|
1475 | - return $markup; |
|
1476 | - } |
|
1477 | - |
|
1478 | - # |
|
1479 | - # Static Methods |
|
1480 | - # |
|
1481 | - |
|
1482 | - static function instance($name = 'default') |
|
1483 | - { |
|
1484 | - if (isset(self::$instances[$name])) |
|
1485 | - { |
|
1486 | - return self::$instances[$name]; |
|
1487 | - } |
|
1488 | - |
|
1489 | - $instance = new static(); |
|
1490 | - |
|
1491 | - self::$instances[$name] = $instance; |
|
1492 | - |
|
1493 | - return $instance; |
|
1494 | - } |
|
986 | + # |
|
987 | + # ~ |
|
988 | + # |
|
989 | + |
|
990 | + public function line($text) |
|
991 | + { |
|
992 | + $markup = ''; |
|
993 | + |
|
994 | + # $excerpt is based on the first occurrence of a marker |
|
995 | + |
|
996 | + while ($excerpt = strpbrk($text, $this->inlineMarkerList)) |
|
997 | + { |
|
998 | + $marker = $excerpt[0]; |
|
999 | + |
|
1000 | + $markerPosition = strpos($text, $marker); |
|
1001 | + |
|
1002 | + $Excerpt = array('text' => $excerpt, 'context' => $text); |
|
1003 | + |
|
1004 | + foreach ($this->InlineTypes[$marker] as $inlineType) |
|
1005 | + { |
|
1006 | + $Inline = $this->{'inline'.$inlineType}($Excerpt); |
|
1007 | + |
|
1008 | + if ( ! isset($Inline)) |
|
1009 | + { |
|
1010 | + continue; |
|
1011 | + } |
|
1012 | + |
|
1013 | + # makes sure that the inline belongs to "our" marker |
|
1014 | + |
|
1015 | + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) |
|
1016 | + { |
|
1017 | + continue; |
|
1018 | + } |
|
1019 | + |
|
1020 | + # sets a default inline position |
|
1021 | + |
|
1022 | + if ( ! isset($Inline['position'])) |
|
1023 | + { |
|
1024 | + $Inline['position'] = $markerPosition; |
|
1025 | + } |
|
1026 | + |
|
1027 | + # the text that comes before the inline |
|
1028 | + $unmarkedText = substr($text, 0, $Inline['position']); |
|
1029 | + |
|
1030 | + # compile the unmarked text |
|
1031 | + $markup .= $this->unmarkedText($unmarkedText); |
|
1032 | + |
|
1033 | + # compile the inline |
|
1034 | + $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); |
|
1035 | + |
|
1036 | + # remove the examined text |
|
1037 | + $text = substr($text, $Inline['position'] + $Inline['extent']); |
|
1038 | + |
|
1039 | + continue 2; |
|
1040 | + } |
|
1041 | + |
|
1042 | + # the marker does not belong to an inline |
|
1043 | + |
|
1044 | + $unmarkedText = substr($text, 0, $markerPosition + 1); |
|
1045 | + |
|
1046 | + $markup .= $this->unmarkedText($unmarkedText); |
|
1047 | + |
|
1048 | + $text = substr($text, $markerPosition + 1); |
|
1049 | + } |
|
1050 | + |
|
1051 | + $markup .= $this->unmarkedText($text); |
|
1052 | + |
|
1053 | + return $markup; |
|
1054 | + } |
|
1055 | + |
|
1056 | + # |
|
1057 | + # ~ |
|
1058 | + # |
|
1059 | + |
|
1060 | + protected function inlineCode($Excerpt) |
|
1061 | + { |
|
1062 | + $marker = $Excerpt['text'][0]; |
|
1063 | + |
|
1064 | + if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches)) |
|
1065 | + { |
|
1066 | + $text = $matches[2]; |
|
1067 | + $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); |
|
1068 | + $text = preg_replace("/[ ]*\n/", ' ', $text); |
|
1069 | + |
|
1070 | + return array( |
|
1071 | + 'extent' => strlen($matches[0]), |
|
1072 | + 'element' => array( |
|
1073 | + 'name' => 'code', |
|
1074 | + 'text' => $text, |
|
1075 | + ), |
|
1076 | + ); |
|
1077 | + } |
|
1078 | + } |
|
1079 | + |
|
1080 | + protected function inlineEmailTag($Excerpt) |
|
1081 | + { |
|
1082 | + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches)) |
|
1083 | + { |
|
1084 | + $url = $matches[1]; |
|
1085 | + |
|
1086 | + if ( ! isset($matches[2])) |
|
1087 | + { |
|
1088 | + $url = 'mailto:' . $url; |
|
1089 | + } |
|
1090 | + |
|
1091 | + return array( |
|
1092 | + 'extent' => strlen($matches[0]), |
|
1093 | + 'element' => array( |
|
1094 | + 'name' => 'a', |
|
1095 | + 'text' => $matches[1], |
|
1096 | + 'attributes' => array( |
|
1097 | + 'href' => $url, |
|
1098 | + ), |
|
1099 | + ), |
|
1100 | + ); |
|
1101 | + } |
|
1102 | + } |
|
1103 | + |
|
1104 | + protected function inlineEmphasis($Excerpt) |
|
1105 | + { |
|
1106 | + if ( ! isset($Excerpt['text'][1])) |
|
1107 | + { |
|
1108 | + return; |
|
1109 | + } |
|
1110 | + |
|
1111 | + $marker = $Excerpt['text'][0]; |
|
1112 | + |
|
1113 | + if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
|
1114 | + { |
|
1115 | + $emphasis = 'strong'; |
|
1116 | + } |
|
1117 | + elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1118 | + { |
|
1119 | + $emphasis = 'em'; |
|
1120 | + } |
|
1121 | + else |
|
1122 | + { |
|
1123 | + return; |
|
1124 | + } |
|
1125 | + |
|
1126 | + return array( |
|
1127 | + 'extent' => strlen($matches[0]), |
|
1128 | + 'element' => array( |
|
1129 | + 'name' => $emphasis, |
|
1130 | + 'handler' => 'line', |
|
1131 | + 'text' => $matches[1], |
|
1132 | + ), |
|
1133 | + ); |
|
1134 | + } |
|
1135 | + |
|
1136 | + protected function inlineEscapeSequence($Excerpt) |
|
1137 | + { |
|
1138 | + if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) |
|
1139 | + { |
|
1140 | + return array( |
|
1141 | + 'markup' => $Excerpt['text'][1], |
|
1142 | + 'extent' => 2, |
|
1143 | + ); |
|
1144 | + } |
|
1145 | + } |
|
1146 | + |
|
1147 | + protected function inlineImage($Excerpt) |
|
1148 | + { |
|
1149 | + if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') |
|
1150 | + { |
|
1151 | + return; |
|
1152 | + } |
|
1153 | + |
|
1154 | + $Excerpt['text']= substr($Excerpt['text'], 1); |
|
1155 | + |
|
1156 | + $Link = $this->inlineLink($Excerpt); |
|
1157 | + |
|
1158 | + if ($Link === null) |
|
1159 | + { |
|
1160 | + return; |
|
1161 | + } |
|
1162 | + |
|
1163 | + $Inline = array( |
|
1164 | + 'extent' => $Link['extent'] + 1, |
|
1165 | + 'element' => array( |
|
1166 | + 'name' => 'img', |
|
1167 | + 'attributes' => array( |
|
1168 | + 'src' => $Link['element']['attributes']['href'], |
|
1169 | + 'alt' => $Link['element']['text'], |
|
1170 | + ), |
|
1171 | + ), |
|
1172 | + ); |
|
1173 | + |
|
1174 | + $Inline['element']['attributes'] += $Link['element']['attributes']; |
|
1175 | + |
|
1176 | + unset($Inline['element']['attributes']['href']); |
|
1177 | + |
|
1178 | + return $Inline; |
|
1179 | + } |
|
1180 | + |
|
1181 | + protected function inlineLink($Excerpt) |
|
1182 | + { |
|
1183 | + $Element = array( |
|
1184 | + 'name' => 'a', |
|
1185 | + 'handler' => 'line', |
|
1186 | + 'text' => null, |
|
1187 | + 'attributes' => array( |
|
1188 | + 'href' => null, |
|
1189 | + 'title' => null, |
|
1190 | + ), |
|
1191 | + ); |
|
1192 | + |
|
1193 | + $extent = 0; |
|
1194 | + |
|
1195 | + $remainder = $Excerpt['text']; |
|
1196 | + |
|
1197 | + if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches)) |
|
1198 | + { |
|
1199 | + $Element['text'] = $matches[1]; |
|
1200 | + |
|
1201 | + $extent += strlen($matches[0]); |
|
1202 | + |
|
1203 | + $remainder = substr($remainder, $extent); |
|
1204 | + } |
|
1205 | + else |
|
1206 | + { |
|
1207 | + return; |
|
1208 | + } |
|
1209 | + |
|
1210 | + if (preg_match('/^[(]((?:[^ ()]|[(][^ )]+[)])+)(?:[ ]+("[^"]*"|\'[^\']*\'))?[)]/', $remainder, $matches)) |
|
1211 | + { |
|
1212 | + $Element['attributes']['href'] = $matches[1]; |
|
1213 | + |
|
1214 | + if (isset($matches[2])) |
|
1215 | + { |
|
1216 | + $Element['attributes']['title'] = substr($matches[2], 1, - 1); |
|
1217 | + } |
|
1218 | + |
|
1219 | + $extent += strlen($matches[0]); |
|
1220 | + } |
|
1221 | + else |
|
1222 | + { |
|
1223 | + if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
|
1224 | + { |
|
1225 | + $definition = strlen($matches[1]) ? $matches[1] : $Element['text']; |
|
1226 | + $definition = strtolower($definition); |
|
1227 | + |
|
1228 | + $extent += strlen($matches[0]); |
|
1229 | + } |
|
1230 | + else |
|
1231 | + { |
|
1232 | + $definition = strtolower($Element['text']); |
|
1233 | + } |
|
1234 | + |
|
1235 | + if ( ! isset($this->DefinitionData['Reference'][$definition])) |
|
1236 | + { |
|
1237 | + return; |
|
1238 | + } |
|
1239 | + |
|
1240 | + $Definition = $this->DefinitionData['Reference'][$definition]; |
|
1241 | + |
|
1242 | + $Element['attributes']['href'] = $Definition['url']; |
|
1243 | + $Element['attributes']['title'] = $Definition['title']; |
|
1244 | + } |
|
1245 | + |
|
1246 | + $Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']); |
|
1247 | + |
|
1248 | + return array( |
|
1249 | + 'extent' => $extent, |
|
1250 | + 'element' => $Element, |
|
1251 | + ); |
|
1252 | + } |
|
1253 | + |
|
1254 | + protected function inlineMarkup($Excerpt) |
|
1255 | + { |
|
1256 | + if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false) |
|
1257 | + { |
|
1258 | + return; |
|
1259 | + } |
|
1260 | + |
|
1261 | + if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches)) |
|
1262 | + { |
|
1263 | + return array( |
|
1264 | + 'markup' => $matches[0], |
|
1265 | + 'extent' => strlen($matches[0]), |
|
1266 | + ); |
|
1267 | + } |
|
1268 | + |
|
1269 | + if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches)) |
|
1270 | + { |
|
1271 | + return array( |
|
1272 | + 'markup' => $matches[0], |
|
1273 | + 'extent' => strlen($matches[0]), |
|
1274 | + ); |
|
1275 | + } |
|
1276 | + |
|
1277 | + if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches)) |
|
1278 | + { |
|
1279 | + return array( |
|
1280 | + 'markup' => $matches[0], |
|
1281 | + 'extent' => strlen($matches[0]), |
|
1282 | + ); |
|
1283 | + } |
|
1284 | + } |
|
1285 | + |
|
1286 | + protected function inlineSpecialCharacter($Excerpt) |
|
1287 | + { |
|
1288 | + if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) |
|
1289 | + { |
|
1290 | + return array( |
|
1291 | + 'markup' => '&', |
|
1292 | + 'extent' => 1, |
|
1293 | + ); |
|
1294 | + } |
|
1295 | + |
|
1296 | + $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); |
|
1297 | + |
|
1298 | + if (isset($SpecialCharacter[$Excerpt['text'][0]])) |
|
1299 | + { |
|
1300 | + return array( |
|
1301 | + 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';', |
|
1302 | + 'extent' => 1, |
|
1303 | + ); |
|
1304 | + } |
|
1305 | + } |
|
1306 | + |
|
1307 | + protected function inlineStrikethrough($Excerpt) |
|
1308 | + { |
|
1309 | + if ( ! isset($Excerpt['text'][1])) |
|
1310 | + { |
|
1311 | + return; |
|
1312 | + } |
|
1313 | + |
|
1314 | + if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) |
|
1315 | + { |
|
1316 | + return array( |
|
1317 | + 'extent' => strlen($matches[0]), |
|
1318 | + 'element' => array( |
|
1319 | + 'name' => 'del', |
|
1320 | + 'text' => $matches[1], |
|
1321 | + 'handler' => 'line', |
|
1322 | + ), |
|
1323 | + ); |
|
1324 | + } |
|
1325 | + } |
|
1326 | + |
|
1327 | + protected function inlineUrl($Excerpt) |
|
1328 | + { |
|
1329 | + if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
1330 | + { |
|
1331 | + return; |
|
1332 | + } |
|
1333 | + |
|
1334 | + if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) |
|
1335 | + { |
|
1336 | + $Inline = array( |
|
1337 | + 'extent' => strlen($matches[0][0]), |
|
1338 | + 'position' => $matches[0][1], |
|
1339 | + 'element' => array( |
|
1340 | + 'name' => 'a', |
|
1341 | + 'text' => $matches[0][0], |
|
1342 | + 'attributes' => array( |
|
1343 | + 'href' => $matches[0][0], |
|
1344 | + ), |
|
1345 | + ), |
|
1346 | + ); |
|
1347 | + |
|
1348 | + return $Inline; |
|
1349 | + } |
|
1350 | + } |
|
1351 | + |
|
1352 | + protected function inlineUrlTag($Excerpt) |
|
1353 | + { |
|
1354 | + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) |
|
1355 | + { |
|
1356 | + $url = str_replace(array('&', '<'), array('&', '<'), $matches[1]); |
|
1357 | + |
|
1358 | + return array( |
|
1359 | + 'extent' => strlen($matches[0]), |
|
1360 | + 'element' => array( |
|
1361 | + 'name' => 'a', |
|
1362 | + 'text' => $url, |
|
1363 | + 'attributes' => array( |
|
1364 | + 'href' => $url, |
|
1365 | + ), |
|
1366 | + ), |
|
1367 | + ); |
|
1368 | + } |
|
1369 | + } |
|
1370 | + |
|
1371 | + # ~ |
|
1372 | + |
|
1373 | + protected function unmarkedText($text) |
|
1374 | + { |
|
1375 | + if ($this->breaksEnabled) |
|
1376 | + { |
|
1377 | + $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
|
1378 | + } |
|
1379 | + else |
|
1380 | + { |
|
1381 | + $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
|
1382 | + $text = str_replace(" \n", "\n", $text); |
|
1383 | + } |
|
1384 | + |
|
1385 | + return $text; |
|
1386 | + } |
|
1387 | + |
|
1388 | + # |
|
1389 | + # Handlers |
|
1390 | + # |
|
1391 | + |
|
1392 | + protected function element(array $Element) |
|
1393 | + { |
|
1394 | + $markup = '<'.$Element['name']; |
|
1395 | + |
|
1396 | + if (isset($Element['attributes'])) |
|
1397 | + { |
|
1398 | + foreach ($Element['attributes'] as $name => $value) |
|
1399 | + { |
|
1400 | + if ($value === null) |
|
1401 | + { |
|
1402 | + continue; |
|
1403 | + } |
|
1404 | + |
|
1405 | + $markup .= ' '.$name.'="'.$value.'"'; |
|
1406 | + } |
|
1407 | + } |
|
1408 | + |
|
1409 | + if (isset($Element['text'])) |
|
1410 | + { |
|
1411 | + $markup .= '>'; |
|
1412 | + |
|
1413 | + if (isset($Element['handler'])) |
|
1414 | + { |
|
1415 | + $markup .= $this->{$Element['handler']}($Element['text']); |
|
1416 | + } |
|
1417 | + else |
|
1418 | + { |
|
1419 | + $markup .= $Element['text']; |
|
1420 | + } |
|
1421 | + |
|
1422 | + $markup .= '</'.$Element['name'].'>'; |
|
1423 | + } |
|
1424 | + else |
|
1425 | + { |
|
1426 | + $markup .= ' />'; |
|
1427 | + } |
|
1428 | + |
|
1429 | + return $markup; |
|
1430 | + } |
|
1431 | + |
|
1432 | + protected function elements(array $Elements) |
|
1433 | + { |
|
1434 | + $markup = ''; |
|
1435 | + |
|
1436 | + foreach ($Elements as $Element) |
|
1437 | + { |
|
1438 | + $markup .= "\n" . $this->element($Element); |
|
1439 | + } |
|
1440 | + |
|
1441 | + $markup .= "\n"; |
|
1442 | + |
|
1443 | + return $markup; |
|
1444 | + } |
|
1445 | + |
|
1446 | + # ~ |
|
1447 | + |
|
1448 | + protected function li($lines) |
|
1449 | + { |
|
1450 | + $markup = $this->lines($lines); |
|
1451 | + |
|
1452 | + $trimmedMarkup = trim($markup); |
|
1453 | + |
|
1454 | + if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') |
|
1455 | + { |
|
1456 | + $markup = $trimmedMarkup; |
|
1457 | + $markup = substr($markup, 3); |
|
1458 | + |
|
1459 | + $position = strpos($markup, "</p>"); |
|
1460 | + |
|
1461 | + $markup = substr_replace($markup, '', $position, 4); |
|
1462 | + } |
|
1463 | + |
|
1464 | + return $markup; |
|
1465 | + } |
|
1466 | + |
|
1467 | + # |
|
1468 | + # Deprecated Methods |
|
1469 | + # |
|
1470 | + |
|
1471 | + function parse($text) |
|
1472 | + { |
|
1473 | + $markup = $this->text($text); |
|
1474 | + |
|
1475 | + return $markup; |
|
1476 | + } |
|
1477 | + |
|
1478 | + # |
|
1479 | + # Static Methods |
|
1480 | + # |
|
1481 | + |
|
1482 | + static function instance($name = 'default') |
|
1483 | + { |
|
1484 | + if (isset(self::$instances[$name])) |
|
1485 | + { |
|
1486 | + return self::$instances[$name]; |
|
1487 | + } |
|
1488 | + |
|
1489 | + $instance = new static(); |
|
1490 | + |
|
1491 | + self::$instances[$name] = $instance; |
|
1492 | + |
|
1493 | + return $instance; |
|
1494 | + } |
|
1495 | 1495 | |
1496 | - private static $instances = array(); |
|
1497 | - |
|
1498 | - # |
|
1499 | - # Fields |
|
1500 | - # |
|
1496 | + private static $instances = array(); |
|
1497 | + |
|
1498 | + # |
|
1499 | + # Fields |
|
1500 | + # |
|
1501 | 1501 | |
1502 | - protected $DefinitionData; |
|
1502 | + protected $DefinitionData; |
|
1503 | 1503 | |
1504 | - # |
|
1505 | - # Read-Only |
|
1504 | + # |
|
1505 | + # Read-Only |
|
1506 | 1506 | |
1507 | - protected $specialCharacters = array( |
|
1508 | - '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', |
|
1509 | - ); |
|
1507 | + protected $specialCharacters = array( |
|
1508 | + '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', |
|
1509 | + ); |
|
1510 | 1510 | |
1511 | - protected $StrongRegex = array( |
|
1512 | - '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', |
|
1513 | - '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us', |
|
1514 | - ); |
|
1511 | + protected $StrongRegex = array( |
|
1512 | + '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', |
|
1513 | + '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us', |
|
1514 | + ); |
|
1515 | 1515 | |
1516 | - protected $EmRegex = array( |
|
1517 | - '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', |
|
1518 | - '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', |
|
1519 | - ); |
|
1516 | + protected $EmRegex = array( |
|
1517 | + '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', |
|
1518 | + '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', |
|
1519 | + ); |
|
1520 | 1520 | |
1521 | - protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?'; |
|
1521 | + protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?'; |
|
1522 | 1522 | |
1523 | - protected $voidElements = array( |
|
1524 | - 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', |
|
1525 | - ); |
|
1523 | + protected $voidElements = array( |
|
1524 | + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', |
|
1525 | + ); |
|
1526 | 1526 | |
1527 | - protected $textLevelElements = array( |
|
1528 | - 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', |
|
1529 | - 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', |
|
1530 | - 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1531 | - 'q', 'rt', 'ins', 'font', 'strong', |
|
1532 | - 's', 'tt', 'sub', 'mark', |
|
1533 | - 'u', 'xm', 'sup', 'nobr', |
|
1534 | - 'var', 'ruby', |
|
1535 | - 'wbr', 'span', |
|
1536 | - 'time', |
|
1537 | - ); |
|
1527 | + protected $textLevelElements = array( |
|
1528 | + 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', |
|
1529 | + 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', |
|
1530 | + 'i', 'rp', 'del', 'code', 'strike', 'marquee', |
|
1531 | + 'q', 'rt', 'ins', 'font', 'strong', |
|
1532 | + 's', 'tt', 'sub', 'mark', |
|
1533 | + 'u', 'xm', 'sup', 'nobr', |
|
1534 | + 'var', 'ruby', |
|
1535 | + 'wbr', 'span', |
|
1536 | + 'time', |
|
1537 | + ); |
|
1538 | 1538 | } |