mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

freaParsedown.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. class freaParsedown extends Parsedown {
  3. function get_BlockTypes() {
  4. return $this->BlockTypes;
  5. }
  6. function deactivate_ol() {
  7. $ol_triggers= array(
  8. "0",
  9. "1",
  10. "2",
  11. "3",
  12. "4",
  13. "5",
  14. "6",
  15. "7",
  16. "8",
  17. "9"
  18. );
  19. foreach ($ol_triggers as $key) {
  20. unset($this->BlockTypes[$key]);
  21. }
  22. }
  23. function add_language_to_link_target($href) {
  24. $f3 = \Base::instance();
  25. $data = [];
  26. $base = substr($href,0,strpos($href,'?') ? : strlen($href));
  27. parse_str(parse_url($href,PHP_URL_QUERY),$data);
  28. $fragment = parse_url($href,PHP_URL_FRAGMENT);
  29. if ($f3->get('LANG') != $f3->get('default_lang')) {
  30. if (!array_key_exists('lang',$data)) {
  31. $data['lang'] = $f3->get('LANG');
  32. }
  33. }
  34. $new = $base;
  35. if (count($data) > 0) {
  36. $new .= "?" . http_build_query($data);
  37. }
  38. if ($fragment) {
  39. $new .= "#" . $fragment;
  40. }
  41. return $new;
  42. }
  43. protected function inlineEmailTag($Excerpt)
  44. {
  45. $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';
  46. $commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
  47. . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
  48. if (strpos($Excerpt['text'], '>') !== false
  49. and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches)
  50. ){
  51. $url = $matches[1];
  52. if ( ! isset($matches[2]))
  53. {
  54. $url = 'mailto:' . $url;
  55. }
  56. return array(
  57. 'extent' => strlen($matches[0]),
  58. 'element' => array(
  59. 'name' => 'a',
  60. 'text' => $matches[1],
  61. 'attributes' => array(
  62. 'href' => $url,
  63. 'data-link-text' => $matches[1],
  64. ),
  65. ),
  66. );
  67. }
  68. }
  69. protected function inlineLink($Excerpt)
  70. {
  71. $Element = array(
  72. 'name' => 'a',
  73. 'handler' => 'line',
  74. 'nonNestables' => array('Url', 'Link'),
  75. 'text' => null,
  76. 'attributes' => array(
  77. 'href' => null,
  78. 'title' => null,
  79. ),
  80. );
  81. $extent = 0;
  82. $remainder = $Excerpt['text'];
  83. if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches))
  84. {
  85. $Element['text'] = $matches[1];
  86. $extent += strlen($matches[0]);
  87. $remainder = substr($remainder, $extent);
  88. }
  89. else
  90. {
  91. return;
  92. }
  93. if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches))
  94. {
  95. $Element['attributes']['href'] = $matches[1];
  96. if (isset($matches[2]))
  97. {
  98. $Element['attributes']['title'] = substr($matches[2], 1, - 1);
  99. }
  100. $extent += strlen($matches[0]);
  101. }
  102. else
  103. {
  104. if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
  105. {
  106. $definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
  107. $definition = strtolower($definition);
  108. $extent += strlen($matches[0]);
  109. }
  110. else
  111. {
  112. $definition = strtolower($Element['text']);
  113. }
  114. if ( ! isset($this->DefinitionData['Reference'][$definition]))
  115. {
  116. return;
  117. }
  118. $Definition = $this->DefinitionData['Reference'][$definition];
  119. $Element['attributes']['href'] = $Definition['url'];
  120. $Element['attributes']['title'] = $Definition['title'];
  121. }
  122. $Element['attributes']['data-link-text'] = $Element['text'];
  123. $url=&$Element['attributes']['href'];
  124. if (strpos($url,':') === FALSE) {
  125. $url = $this->add_language_to_link_target($url);
  126. }
  127. return array(
  128. 'extent' => $extent,
  129. 'element' => $Element,
  130. );
  131. }
  132. protected function inlineUrl($Excerpt)
  133. {
  134. if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
  135. {
  136. return;
  137. }
  138. if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
  139. {
  140. $url = $matches[0][0];
  141. $Inline = array(
  142. 'extent' => strlen($matches[0][0]),
  143. 'position' => $matches[0][1],
  144. 'element' => array(
  145. 'name' => 'a',
  146. 'text' => $url,
  147. 'attributes' => array(
  148. 'href' => $url,
  149. 'data-link-text' => $url,
  150. ),
  151. ),
  152. );
  153. return $Inline;
  154. }
  155. }
  156. protected function inlineUrlTag($Excerpt)
  157. {
  158. if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
  159. {
  160. $url = $matches[1];
  161. return array(
  162. 'extent' => strlen($matches[0]),
  163. 'element' => array(
  164. 'name' => 'a',
  165. 'text' => $url,
  166. 'attributes' => array(
  167. 'href' => $url,
  168. 'data-link-text' => $url,
  169. ),
  170. ),
  171. );
  172. }
  173. }
  174. }