| 1: | <?php declare(strict_types=1); | 
| 2: |  | 
| 3: | namespace Salient\Console\Format; | 
| 4: |  | 
| 5: | use Salient\Contract\Console\Format\TagAttributesInterface; | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: | class LoopbackFormat extends AbstractFormat | 
| 13: | { | 
| 14: | use EncloseTrait; | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: | public function apply(string $string, $attributes = null): string | 
| 20: | { | 
| 21: | if ($string === '') { | 
| 22: | return ''; | 
| 23: | } | 
| 24: |  | 
| 25: | $before = $this->Before; | 
| 26: | $after = $this->After; | 
| 27: |  | 
| 28: | if ( | 
| 29: | $attributes instanceof TagAttributesInterface | 
| 30: | && $attributes->getOpenTag() !== '' | 
| 31: | ) { | 
| 32: | $before = $attributes->getOpenTag(); | 
| 33: | $after = $before === '<' ? '>' : $attributes->getOpenTag(); | 
| 34: | } | 
| 35: |  | 
| 36: | if ($before === '##') { | 
| 37: | return $this->enclose($string, '## ', ' ##'); | 
| 38: | } | 
| 39: |  | 
| 40: | if ($this->Before === '```') { | 
| 41: | return $attributes instanceof TagAttributesInterface | 
| 42: | ? $this->enclose( | 
| 43: | $string, | 
| 44: | $before . $attributes->getInfoString() . "\n", | 
| 45: | "\n" . $attributes->getIndent() . $after, | 
| 46: | ) | 
| 47: | : $this->enclose( | 
| 48: | $string, | 
| 49: | $before . "\n", | 
| 50: | "\n" . $after, | 
| 51: | ); | 
| 52: | } | 
| 53: |  | 
| 54: | return $this->enclose($string, $before, $after); | 
| 55: | } | 
| 56: |  | 
| 57: |  | 
| 58: |  | 
| 59: |  | 
| 60: | protected static function getTagFormats(): ?TagFormats | 
| 61: | { | 
| 62: | return (new TagFormats(false)) | 
| 63: | ->withFormat(self::TAG_HEADING, new self('***', '***')) | 
| 64: | ->withFormat(self::TAG_BOLD, new self('**', '**')) | 
| 65: | ->withFormat(self::TAG_ITALIC, new self('*', '*')) | 
| 66: | ->withFormat(self::TAG_UNDERLINE, new self('<', '>')) | 
| 67: | ->withFormat(self::TAG_LOW_PRIORITY, new self('~~', '~~')) | 
| 68: | ->withFormat(self::TAG_CODE_SPAN, new self('`', '`')) | 
| 69: | ->withFormat(self::TAG_CODE_BLOCK, new self('```', '```')); | 
| 70: | } | 
| 71: | } | 
| 72: |  |