feat: add support for custom attributes

- Use MW core sanitizer to sanitize attributes to keep feature parity with core sanitizier
- Simplify HTML attribute handling

Closes: #194, #183
This commit is contained in:
alistair3149 2024-11-22 16:02:46 -05:00
parent 422c60a573
commit f553e95d0a
No known key found for this signature in database
2 changed files with 14 additions and 6 deletions

View file

@ -76,13 +76,21 @@ class Tabber {
* @return string HTML
*/
public static function render( string $input, int $count, array $args, Parser $parser, PPFrame $frame ): string {
$arr = explode( '|-|', $input );
$data = [
'id' => isset( $args['id'] ) ? $args['id'] : "tabber-$count",
'class' => isset( $args['class'] ) ? $args['class'] : '',
'array-tabs' => []
$attr = [
'id' => "tabber-$count",
'class' => 'tabber tabber--init'
];
foreach( $args as $attribute => $value ) {
$attr = Sanitizer::mergeAttributes( $attr, [ $attribute => $value ] );
}
$data = [
'array-tabs' => [],
'html-attributes' => Sanitizer::safeEncodeTagAttributes( Sanitizer::validateTagAttributes( $attr, 'div' ) )
];
$arr = explode( '|-|', $input );
foreach ( $arr as $tab ) {
$tabData = self::getTabData( $tab, $count, $parser, $frame );
if ( $tabData === [] ) {

View file

@ -1,4 +1,4 @@
<div id="{{id}}" class='tabber tabber--init {{class}}'>{{!
<div {{{html-attributes}}}'>{{!
}}<header class="tabber__header">{{!
}}<button class="tabber__header__prev" aria-hidden="true"></button>{{!
}}<nav class="tabber__tabs" role="tablist">{{!