KD2 Framework  Check-in [f8acad40e9]

Overview
Comment:Markdown: handle contenful extensions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f8acad40e95828c0422a299803b3acddf1fc8405
User & Date: bohwaz on 2023-05-31 21:44:50
Other Links: manifest | tags
Context
2023-06-01
17:15
UserSession: implement hasRememberMeCookie method check-in: 219a879405 user: bohwaz tags: trunk
2023-05-31
21:44
Markdown: handle contenful extensions check-in: f8acad40e9 user: bohwaz tags: trunk
14:05
In some rare cases, the JPEG file may be corrupted check-in: 2e2dbcdc50 user: bohwaz tags: trunk
Changes

Modified src/lib/KD2/HTML/Markdown.php from [07028ac767] to [fcaf39f809].

293
294
295
296
297
298
299
300
301
302
303
304





305
306
307
308
309
310
311
312
313
314

















315
316
317
318
319
320
321
	/**
	 * Block extensions
	 */
	protected function blockExtension(array $line): ?array
	{
		$line = $line['text'];

		if (strpos($line, '<<') === 0 && preg_match('/^<<<?(\/?[a-z_]+)((?:(?!>>>?).)*?)(>>>?$|$)/is', trim($line), $match)) {
			$text = $this->callExtension($match[1], true, $match[2]);

			return [
				'char'    => $line[0],





				'element' => [
					'rawHtml'                => $text,
					'allowRawHtmlInSafeMode' => true,
				],
				'complete' => true,
			];
		}

		return null;
	}


















	/**
	 * Class block:
	 * {{class1 class2
	 * > My block
	 * }}
	 */







|
|


|
>
>
>
>
>
|



<





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
	/**
	 * Block extensions
	 */
	protected function blockExtension(array $line): ?array
	{
		$line = $line['text'];

		if (strpos($line, '<<') === 0 && preg_match('/^<<<?(\/?[a-z_]+)((?:(?!>>>?).)*?)(>>>?$|$)/ism', trim($line), $match)) {
			$text = $match[3] ? $this->callExtension($match[1], true, $match[2]) : '';

			return [
				'char'       => $line[0],
				'ext_name'   => $match[1],
				'ext_params' => $match[2],
				'ext_content' => '',
				'complete'   => $match[3] ? false : true,
				'closed'     => $match[3] ? true : false,
				'element'    => [
					'rawHtml'                => $text,
					'allowRawHtmlInSafeMode' => true,
				],

			];
		}

		return null;
	}

	protected function blockExtensionContinue(array $line, array $block): ?array
	{
		if (!empty($block['closed'])) {
			return null;
		}

		if (strpos($line['text'], '>>') !== false) {
			$block['closed'] = true;
			$block['element']['rawHtml'] = $this->callExtension($block['ext_name'], true, $block['ext_params'], rtrim($block['ext_content']));
		}
		else {
			$block['ext_content'] .= $line['body'] . "\n";
		}

		return $block;
	}

	/**
	 * Class block:
	 * {{class1 class2
	 * > My block
	 * }}
	 */