12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace cebe\markdown\inline;
- trait EmphStrongTrait
- {
-
- protected function parseEmphStrong($text)
- {
- $marker = $text[0];
- if (!isset($text[1])) {
- return [['text', $text[0]], 1];
- }
- if ($marker == $text[1]) {
-
-
-
-
- if (strpos($text, $marker . $marker, 2) === false) {
- return [['text', $text[0] . $text[1]], 2];
- }
- if ($marker === '*' && preg_match('/^[*]{2}((?>\\\\[*]|[^*]|[*][^*]*[*])+?)[*]{2}/s', $text, $matches) ||
- $marker === '_' && preg_match('/^__((?>\\\\_|[^_]|_[^_]*_)+?)__/us', $text, $matches)) {
- return [
- [
- 'strong',
- $this->parseInline($matches[1]),
- ],
- strlen($matches[0])
- ];
- }
- } else {
-
-
-
-
- if (strpos($text, $marker, 1) === false) {
- return [['text', $text[0]], 1];
- }
- if ($marker === '*' && preg_match('/^[*]((?>\\\\[*]|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*][^*])/s', $text, $matches) ||
- $marker === '_' && preg_match('/^_((?>\\\\_|[^_]|__[^_]*__)+?)_(?!_[^_])\b/us', $text, $matches)) {
-
- if ($matches[1] === '' || $matches[1] === ' ') {
- return [['text', $text[0]], 1];
- }
- return [
- [
- 'emph',
- $this->parseInline($matches[1]),
- ],
- strlen($matches[0])
- ];
- }
- }
- return [['text', $text[0]], 1];
- }
- protected function renderStrong($block)
- {
- return '<strong>' . $this->renderAbsy($block[1]) . '</strong>';
- }
- protected function renderEmph($block)
- {
- return '<em>' . $this->renderAbsy($block[1]) . '</em>';
- }
- abstract protected function parseInline($text);
- abstract protected function renderAbsy($blocks);
- }
|