| 1 |
<?php |
| 2 |
namespace MediaWiki\Extension\Math\WikiTexVC\MMLnodes; |
| 3 |
|
| 4 |
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\Tag; |
| 5 |
use MediaWiki\Html\Html; |
| 6 |
|
| 7 |
class MMLbase { |
| 8 |
private string $name; |
| 9 |
private array $attributes; |
| 10 |
|
| 11 |
public function __construct( string $name, string $texclass = '', array $attributes = [] ) { |
| 12 |
$this->name = $name; |
| 13 |
$this->attributes = $attributes; |
| 14 |
if ( $texclass !== '' ) { |
| 15 |
$this->attributes[ TAG::CLASSTAG ] = $texclass; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
public function name(): string { |
| 20 |
return $this->name; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function encapsulateRaw( string $input ): string { |
| 30 |
return HTML::rawElement( $this->name, $this->attributes, $input ); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function encapsulate( string $input = '' ): string { |
| 40 |
return HTML::element( $this->name, $this->attributes, $input ); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function getStart(): string { |
| 48 |
return HTML::openElement( $this->name, $this->attributes ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function getEmpty(): string { |
| 57 |
return substr( $this->getStart(), 0, -1 ) |
| 58 |
. '/>'; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function getEnd(): string { |
| 66 |
return HTML::closeElement( $this->name ); |
| 67 |
} |
| 68 |
} |