@@ -25,8 +25,8 @@ |
||
| 25 | 25 | private $style; |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * @param string $style Either 'HTML', 'Markdown' or 'MarkdownV2'. |
|
| 29 | - */ |
|
| 28 | + * @param string $style Either 'HTML', 'Markdown' or 'MarkdownV2'. |
|
| 29 | + */ |
|
| 30 | 30 | public function __construct(string $style = 'HTML') |
| 31 | 31 | { |
| 32 | 32 | $this->style = $style; |
@@ -140,31 +140,31 @@ discard block |
||
| 140 | 140 | $str_split_unicode = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); |
| 141 | 141 | $new_string_split = []; |
| 142 | 142 | $joiner = false; |
| 143 | - for ($i = 0, $c = count($str_split_unicode); $i < $c; $i++) //loop the array |
|
| 143 | + for ($i = 0, $c = count($str_split_unicode); $i < $c; $i++) { |
|
| 144 | + //loop the array |
|
| 144 | 145 | { |
| 145 | - $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); //Get the string rappresentation of the unicode char |
|
| 146 | + $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); |
|
| 147 | + } |
|
| 148 | + //Get the string rappresentation of the unicode char |
|
| 146 | 149 | if ($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") |
| 147 | 150 | { |
| 148 | 151 | //Manage the modifiers |
| 149 | 152 | $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the modifier to the previous char |
| 150 | - } |
|
| 151 | - else |
|
| 153 | + } else |
|
| 152 | 154 | { |
| 153 | 155 | if ($codepoint == "200d") |
| 154 | 156 | { |
| 155 | 157 | //Manage the Zero Width Joiner |
| 156 | 158 | $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the ZWJ to the previous char |
| 157 | 159 | $joiner = true; |
| 158 | - } |
|
| 159 | - else |
|
| 160 | + } else |
|
| 160 | 161 | { |
| 161 | 162 | if ($joiner) |
| 162 | 163 | { |
| 163 | 164 | //If previous one was a ZWJ |
| 164 | 165 | $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend to the previous char |
| 165 | 166 | $joiner = false; |
| 166 | - } |
|
| 167 | - else |
|
| 167 | + } else |
|
| 168 | 168 | { |
| 169 | 169 | $new_string_split[] = $str_split_unicode[$i]; //New char |
| 170 | 170 | } |
@@ -193,38 +193,31 @@ discard block |
||
| 193 | 193 | if ($char == $this->getEntityStartString($entity)) |
| 194 | 194 | { |
| 195 | 195 | return $char."\\".$char.$char; |
| 196 | - } |
|
| 197 | - else |
|
| 196 | + } else |
|
| 198 | 197 | { |
| 199 | 198 | return $char; |
| 200 | 199 | } |
| 201 | - } |
|
| 202 | - else |
|
| 200 | + } else |
|
| 203 | 201 | { |
| 204 | 202 | return $char; |
| 205 | 203 | } |
| 206 | - } |
|
| 207 | - else |
|
| 204 | + } else |
|
| 208 | 205 | { |
| 209 | 206 | if ($char == '*' || $char == '_' || $char == '[' || $char == '`') |
| 210 | 207 | { |
| 211 | 208 | return "\\".$char; |
| 212 | - } |
|
| 213 | - else |
|
| 209 | + } else |
|
| 214 | 210 | { |
| 215 | 211 | return $char; |
| 216 | 212 | } |
| 217 | 213 | } |
| 218 | - } |
|
| 219 | - else if ($this->style == 'HTML') |
|
| 214 | + } else if ($this->style == 'HTML') |
|
| 220 | 215 | { |
| 221 | 216 | return ($char == '<' ? '<' : ($char == '>' ? '>' : ($char == '&' ? '&' : $char))); |
| 222 | - } |
|
| 223 | - else if ($this->style == 'MarkdownV2') |
|
| 217 | + } else if ($this->style == 'MarkdownV2') |
|
| 224 | 218 | { |
| 225 | 219 | return (in_array($char, array('_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\')) ? '\\'.$char : $char); |
| 226 | - } |
|
| 227 | - else |
|
| 220 | + } else |
|
| 228 | 221 | { |
| 229 | 222 | return $char; |
| 230 | 223 | } |
@@ -271,8 +264,7 @@ discard block |
||
| 271 | 264 | break; |
| 272 | 265 | } |
| 273 | 266 | } |
| 274 | - } |
|
| 275 | - else if ($this->style == 'HTML') |
|
| 267 | + } else if ($this->style == 'HTML') |
|
| 276 | 268 | { |
| 277 | 269 | switch ($entity->type) |
| 278 | 270 | { |
@@ -326,8 +318,7 @@ discard block |
||
| 326 | 318 | break; |
| 327 | 319 | } |
| 328 | 320 | } |
| 329 | - } |
|
| 330 | - else if ($this->style == 'MarkdownV2') |
|
| 321 | + } else if ($this->style == 'MarkdownV2') |
|
| 331 | 322 | { |
| 332 | 323 | switch ($entity->type) |
| 333 | 324 | { |
@@ -377,8 +368,7 @@ discard block |
||
| 377 | 368 | break; |
| 378 | 369 | } |
| 379 | 370 | } |
| 380 | - } |
|
| 381 | - else |
|
| 371 | + } else |
|
| 382 | 372 | { |
| 383 | 373 | //Exception |
| 384 | 374 | } |
@@ -401,10 +391,11 @@ discard block |
||
| 401 | 391 | } |
| 402 | 392 | } |
| 403 | 393 | } |
| 404 | - if (count($entities) > 0) |
|
| 405 | - return $entities; |
|
| 406 | - else |
|
| 407 | - return false; |
|
| 394 | + if (count($entities) > 0) { |
|
| 395 | + return $entities; |
|
| 396 | + } else { |
|
| 397 | + return false; |
|
| 398 | + } |
|
| 408 | 399 | } |
| 409 | 400 | |
| 410 | 401 | /** |
@@ -448,8 +439,7 @@ discard block |
||
| 448 | 439 | break; |
| 449 | 440 | } |
| 450 | 441 | } |
| 451 | - } |
|
| 452 | - else if ($this->style == 'HTML') |
|
| 442 | + } else if ($this->style == 'HTML') |
|
| 453 | 443 | { |
| 454 | 444 | switch ($entity->type) |
| 455 | 445 | { |
@@ -499,8 +489,7 @@ discard block |
||
| 499 | 489 | break; |
| 500 | 490 | } |
| 501 | 491 | } |
| 502 | - } |
|
| 503 | - else if ($this->style == 'MarkdownV2') |
|
| 492 | + } else if ($this->style == 'MarkdownV2') |
|
| 504 | 493 | { |
| 505 | 494 | switch ($entity->type) |
| 506 | 495 | { |
@@ -550,8 +539,7 @@ discard block |
||
| 550 | 539 | break; |
| 551 | 540 | } |
| 552 | 541 | } |
| 553 | - } |
|
| 554 | - else |
|
| 542 | + } else |
|
| 555 | 543 | { |
| 556 | 544 | //Exception |
| 557 | 545 | } |
@@ -574,10 +562,11 @@ discard block |
||
| 574 | 562 | } |
| 575 | 563 | } |
| 576 | 564 | } |
| 577 | - if (count($entities) > 0) |
|
| 578 | - return array_reverse($entities); |
|
| 579 | - else |
|
| 580 | - return false; |
|
| 565 | + if (count($entities) > 0) { |
|
| 566 | + return array_reverse($entities); |
|
| 567 | + } else { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 581 | 570 | } |
| 582 | 571 | |
| 583 | 572 | /** |