| 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 ManPageFormat 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: | $tag = $attributes instanceof TagAttributesInterface |
| 29: | ? $attributes->getOpenTag() |
| 30: | : ''; |
| 31: | |
| 32: | if ($tag === '##') { |
| 33: | return $this->enclose($string, '# ', ''); |
| 34: | } |
| 35: | |
| 36: | if ($tag === '_') { |
| 37: | return $this->enclose($string, '', ''); |
| 38: | } |
| 39: | |
| 40: | if ($before === '`') { |
| 41: | return $this->enclose($string, '**`', '`**'); |
| 42: | } |
| 43: | |
| 44: | if ($before === '```') { |
| 45: | return $attributes instanceof TagAttributesInterface |
| 46: | ? $this->enclose( |
| 47: | $string, |
| 48: | $before . $attributes->getInfoString() . "\n", |
| 49: | "\n" . $attributes->getIndent() . $after, |
| 50: | ) |
| 51: | : $this->enclose( |
| 52: | $string, |
| 53: | $before . "\n", |
| 54: | "\n" . $after, |
| 55: | ); |
| 56: | } |
| 57: | |
| 58: | return $this->enclose($string, $before, $after); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | protected static function getTagFormats(): ?TagFormats |
| 65: | { |
| 66: | return (new TagFormats(false, true)) |
| 67: | ->withFormat(self::TAG_HEADING, new self('***', '***')) |
| 68: | ->withFormat(self::TAG_BOLD, new self('**', '**')) |
| 69: | ->withFormat(self::TAG_ITALIC, new self('*', '*')) |
| 70: | ->withFormat(self::TAG_UNDERLINE, new self('*', '*')) |
| 71: | ->withFormat(self::TAG_LOW_PRIORITY, new self('', '')) |
| 72: | ->withFormat(self::TAG_CODE_SPAN, new self('`', '`')) |
| 73: | ->withFormat(self::TAG_CODE_BLOCK, new self('```', '```')); |
| 74: | } |
| 75: | } |
| 76: | |