Blame view

vendor/cebe/markdown/inline/CodeTrait.php 905 Bytes
abf1649b   andryeyev   Чистая установка ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  <?php
  /**
   * @copyright Copyright (c) 2014 Carsten Brandt
   * @license https://github.com/cebe/markdown/blob/master/LICENSE
   * @link https://github.com/cebe/markdown#readme
   */
  
  namespace cebe\markdown\inline;
  
  /**
   * Adds inline code elements
   */
  trait CodeTrait
  {
  	/**
  	 * Parses an inline code span `` ` ``.
  	 * @marker `
  	 */
  	protected function parseInlineCode($text)
  	{
  		if (preg_match('/^(``+)\s(.+?)\s\1/s', $text, $matches)) { // code with enclosed backtick
  			return [
  				[
  					'inlineCode',
  					$matches[2],
  				],
  				strlen($matches[0])
  			];
  		} elseif (preg_match('/^`(.+?)`/s', $text, $matches)) {
  			return [
  				[
  					'inlineCode',
  					$matches[1],
  				],
  				strlen($matches[0])
  			];
  		}
  		return [['text', $text[0]], 1];
  	}
  
  	protected function renderInlineCode($block)
  	{
  		return '<code>' . htmlspecialchars($block[1], ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</code>';
  	}
  }